From 1b56144d2b18f7330c0d79e847b52ceafdf53de6 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 8 Sep 2012 21:44:56 -0700 Subject: Revert "Revert "Started to work on move to ActionBarSherlock"" This reverts commit 00646f4aacd09c24d13170fe78bb144f1a98c4f6. --- .../dsub/activity/DownloadActivity.java | 15 +-- .../daneren2005/dsub/activity/MainActivity.java | 103 ++++++++++----------- .../dsub/activity/SelectAlbumActivity.java | 70 +++++++------- .../dsub/activity/SelectArtistActivity.java | 76 +++++++-------- .../dsub/activity/SelectPlaylistActivity.java | 61 ++++++------ .../dsub/activity/SubsonicTabActivity.java | 61 ++---------- 6 files changed, 162 insertions(+), 224 deletions(-) (limited to 'subsonic-android/src/github') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java index a657b7eb..4a3dd9bc 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java @@ -40,9 +40,6 @@ import android.view.Display; import android.view.GestureDetector; import android.view.GestureDetector.OnGestureListener; import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; @@ -58,6 +55,10 @@ import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; import android.widget.ViewFlipper; +import com.actionbarsherlock.app.SherlockActivity; +import com.actionbarsherlock.view.Menu; +import com.actionbarsherlock.view.MenuItem; +import com.actionbarsherlock.view.MenuInflater; import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.domain.PlayerState; @@ -487,7 +488,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi @Override public boolean onCreateOptionsMenu(Menu menu) { - MenuInflater inflater = getMenuInflater(); + MenuInflater inflater = getSupportMenuInflater(); inflater.inflate(R.menu.nowplaying, menu); return true; } @@ -507,14 +508,14 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi return super.onPrepareOptionsMenu(menu); } - @Override + /*@Override public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, view, menuInfo); if (view == playlistView) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; DownloadFile downloadFile = (DownloadFile) playlistView.getItemAtPosition(info.position); - MenuInflater inflater = getMenuInflater(); + MenuInflater inflater = getSupportMenuInflater(); inflater.inflate(R.menu.nowplaying_context, menu); if (downloadFile.getSong().getParent() == null) { @@ -532,7 +533,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); DownloadFile downloadFile = (DownloadFile) playlistView.getItemAtPosition(info.position); return menuItemSelected(menuItem.getItemId(), downloadFile) || super.onContextItemSelected(menuItem); - } + }*/ @Override public boolean onOptionsItemSelected(MenuItem menuItem) { diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java index e5958e57..60532868 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java @@ -28,6 +28,9 @@ import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.MergeAdapter; import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.util.FileUtil; +import com.actionbarsherlock.view.Menu; +import com.actionbarsherlock.view.MenuItem; +import com.actionbarsherlock.view.MenuInflater; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -35,7 +38,6 @@ import android.os.Bundle; import android.preference.PreferenceManager; import android.view.ContextMenu; import android.view.LayoutInflater; -import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ImageButton; @@ -115,63 +117,52 @@ public class MainActivity extends SubsonicTabActivity { } } }); - - // Title: Subsonic + + // Title: Subsonic setTitle(R.string.common_appname); - // Button 1: shuffle - ImageButton actionShuffleButton = (ImageButton)findViewById(R.id.action_button_1); - actionShuffleButton.setImageResource(R.drawable.action_shuffle); - actionShuffleButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(MainActivity.this, DownloadActivity.class); + // Remember the current theme. + theme = Util.getTheme(this); + + showInfoDialog(); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getSupportMenuInflater(); + inflater.inflate(R.menu.main, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + Intent intent; + switch (item.getItemId()) { + case R.id.menu_shuffle: + intent = new Intent(MainActivity.this, DownloadActivity.class); intent.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, true); Util.startActivityWithoutTransition(MainActivity.this, intent); - } - }); - - // Button 2: search - ImageButton actionSearchButton = (ImageButton)findViewById(R.id.action_button_2); - actionSearchButton.setImageResource(R.drawable.action_search); - actionSearchButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(MainActivity.this, SearchActivity.class); + return true; + case R.id.menu_search: + intent = new Intent(MainActivity.this, SearchActivity.class); intent.putExtra(Constants.INTENT_EXTRA_REQUEST_SEARCH, true); Util.startActivityWithoutTransition(MainActivity.this, intent); - } - }); - - // Button 3: Help - ImageButton actionHelpButton = (ImageButton)findViewById(R.id.action_button_3); - actionHelpButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - startActivity(new Intent(MainActivity.this, HelpActivity.class)); - } - }); - - // Button 4: Settings - ImageButton actionSettingsButton = (ImageButton)findViewById(R.id.action_button_4); - actionSettingsButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - startActivity(new Intent(MainActivity.this, SettingsActivity.class)); - - /*LayoutInflater inflater = (LayoutInflater)MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - PopupWindow pw = new PopupWindow(inflater.inflate(R.layout.overflow_menu, null, false), 100, 100, true); - pw.showAsDropDown(findViewById(R.id.action_button_4));*/ - - /*PopupWindow window = new PopupWindow(findViewById(R.layout.overflow_menu)); - window.showAsDropDown(findViewById(R.id.action_button_2));*/ - } - }); - - // Remember the current theme. - theme = Util.getTheme(this); + return true; + case R.id.menu_exit: + intent = new Intent(this, MainActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + intent.putExtra(Constants.INTENT_EXTRA_NAME_EXIT, true); + Util.startActivityWithoutTransition(this, intent); + return true; + case R.id.menu_settings: + startActivity(new Intent(this, SettingsActivity.class)); + return true; + case R.id.menu_help: + startActivity(new Intent(this, HelpActivity.class)); + return true; + } - showInfoDialog(); + return false; } private void loadSettings() { @@ -198,10 +189,10 @@ public class MainActivity extends SubsonicTabActivity { public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, view, menuInfo); - MenuItem menuItem1 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_1, MENU_ITEM_SERVER_1, Util.getServerName(this, 1)); - MenuItem menuItem2 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_2, MENU_ITEM_SERVER_2, Util.getServerName(this, 2)); - MenuItem menuItem3 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_3, MENU_ITEM_SERVER_3, Util.getServerName(this, 3)); - MenuItem menuItem4 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_OFFLINE, MENU_ITEM_OFFLINE, Util.getServerName(this, 0)); + android.view.MenuItem menuItem1 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_1, MENU_ITEM_SERVER_1, Util.getServerName(this, 1)); + android.view.MenuItem menuItem2 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_2, MENU_ITEM_SERVER_2, Util.getServerName(this, 2)); + android.view.MenuItem menuItem3 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_3, MENU_ITEM_SERVER_3, Util.getServerName(this, 3)); + android.view.MenuItem menuItem4 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_OFFLINE, MENU_ITEM_OFFLINE, Util.getServerName(this, 0)); menu.setGroupCheckable(MENU_GROUP_SERVER, true, true); menu.setHeaderTitle(R.string.main_select_server); @@ -222,7 +213,7 @@ public class MainActivity extends SubsonicTabActivity { } @Override - public boolean onContextItemSelected(MenuItem menuItem) { + public boolean onContextItemSelected(android.view.MenuItem menuItem) { switch (menuItem.getItemId()) { case MENU_ITEM_OFFLINE: setActiveServer(0); diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java index 108dcf9c..31c4e728 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java @@ -34,6 +34,7 @@ import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.ListView; +import com.actionbarsherlock.view.Menu; import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.service.DownloadFile; @@ -177,45 +178,40 @@ public class SelectAlbumActivity extends SubsonicTabActivity { } else { getMusicDirectory(id, name); } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater(); + inflater.inflate(R.menu.select_album, menu); + return true; + } - // Button 1: play all - playAllButton = (ImageButton) findViewById(R.id.action_button_1); - playAllButton.setImageResource(R.drawable.action_play_all); - playAllButton.setVisibility(View.GONE); - playAllButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - playAll(false); - } - }); + @Override + public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { + Intent intent; + switch (item.getItemId()) { + case R.id.menu_play_all: + playAll(false); + return true; + case R.id.menu_refresh: + refresh(); + return true; + case R.id.menu_exit: + intent = new Intent(this, MainActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + intent.putExtra(Constants.INTENT_EXTRA_NAME_EXIT, true); + Util.startActivityWithoutTransition(this, intent); + return true; + case R.id.menu_settings: + startActivity(new Intent(this, SettingsActivity.class)); + return true; + case R.id.menu_help: + startActivity(new Intent(this, HelpActivity.class)); + return true; + } - // Button 2: refresh - ImageButton refreshButton = (ImageButton) findViewById(R.id.action_button_2); - refreshButton.setImageResource(R.drawable.action_refresh); - refreshButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - refresh(); - } - }); - - // Button 3: Help - ImageButton actionHelpButton = (ImageButton)findViewById(R.id.action_button_3); - actionHelpButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - startActivity(new Intent(SelectAlbumActivity.this, HelpActivity.class)); - } - }); - - // Button 4: Settings - ImageButton actionSettingsButton = (ImageButton)findViewById(R.id.action_button_4); - actionSettingsButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - startActivity(new Intent(SelectAlbumActivity.this, SettingsActivity.class)); - } - }); + return false; } private void playAll(final boolean shuffle) { diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SelectArtistActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SelectArtistActivity.java index 8b32ff3a..bee76641 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SelectArtistActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SelectArtistActivity.java @@ -30,6 +30,7 @@ import android.widget.AdapterView; import android.widget.ImageButton; import android.widget.ListView; import android.widget.TextView; +import com.actionbarsherlock.view.Menu; import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.Artist; import github.daneren2005.dsub.domain.Indexes; @@ -73,51 +74,46 @@ public class SelectArtistActivity extends SubsonicTabActivity implements Adapter } registerForContextMenu(artistList); + setTitle(Util.isOffline(this) ? R.string.music_library_label_offline : R.string.music_library_label); - setTitle(Util.isOffline(this) ? R.string.music_library_label_offline : R.string.music_library_label); + musicFolders = null; + load(); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater(); + inflater.inflate(R.menu.select_artist, menu); + return true; + } - // Button 1: shuffle - ImageButton shuffleButton = (ImageButton) findViewById(R.id.action_button_1); - shuffleButton.setImageResource(R.drawable.action_shuffle); - shuffleButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(SelectArtistActivity.this, DownloadActivity.class); + @Override + public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { + Intent intent; + switch (item.getItemId()) { + case R.id.menu_refresh: + refresh(); + return true; + case R.id.menu_shuffle: + intent = new Intent(SelectArtistActivity.this, DownloadActivity.class); intent.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, true); Util.startActivityWithoutTransition(SelectArtistActivity.this, intent); - } - }); - - // Button 2: refresh - ImageButton refreshButton = (ImageButton) findViewById(R.id.action_button_2); - refreshButton.setImageResource(R.drawable.action_refresh); - refreshButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - refresh(); - } - }); - - // Button 3: Help - ImageButton actionHelpButton = (ImageButton)findViewById(R.id.action_button_3); - actionHelpButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - startActivity(new Intent(SelectArtistActivity.this, HelpActivity.class)); - } - }); - - // Button 4: Settings - ImageButton actionSettingsButton = (ImageButton)findViewById(R.id.action_button_4); - actionSettingsButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - startActivity(new Intent(SelectArtistActivity.this, SettingsActivity.class)); - } - }); + return true; + case R.id.menu_exit: + intent = new Intent(this, MainActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + intent.putExtra(Constants.INTENT_EXTRA_NAME_EXIT, true); + Util.startActivityWithoutTransition(this, intent); + return true; + case R.id.menu_settings: + startActivity(new Intent(this, SettingsActivity.class)); + return true; + case R.id.menu_help: + startActivity(new Intent(this, HelpActivity.class)); + return true; + } - musicFolders = null; - load(); + return false; } private void refresh() { diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java index a299b84b..f515d5be 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java @@ -61,39 +61,38 @@ public class SelectPlaylistActivity extends SubsonicTabActivity implements Adapt // Title: Playlists setTitle(R.string.playlist_label); - // Button 1: gone - ImageButton searchButton = (ImageButton)findViewById(R.id.action_button_1); - searchButton.setVisibility(View.GONE); - - // Button 2: refresh - ImageButton refreshButton = (ImageButton) findViewById(R.id.action_button_2); - refreshButton.setImageResource(R.drawable.action_refresh); - refreshButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { + load(); + } + + @Override + public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) { + com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater(); + inflater.inflate(R.menu.select_playlist, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { + Intent intent; + switch (item.getItemId()) { + case R.id.menu_refresh: refresh(); - } - }); - - // Button 3: Help - ImageButton actionHelpButton = (ImageButton)findViewById(R.id.action_button_3); - actionHelpButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - startActivity(new Intent(SelectPlaylistActivity.this, HelpActivity.class)); - } - }); - - // Button 4: Settings - ImageButton actionSettingsButton = (ImageButton)findViewById(R.id.action_button_4); - actionSettingsButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - startActivity(new Intent(SelectPlaylistActivity.this, SettingsActivity.class)); - } - }); + return true; + case R.id.menu_exit: + intent = new Intent(this, MainActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + intent.putExtra(Constants.INTENT_EXTRA_NAME_EXIT, true); + Util.startActivityWithoutTransition(this, intent); + return true; + case R.id.menu_settings: + startActivity(new Intent(this, SettingsActivity.class)); + return true; + case R.id.menu_help: + startActivity(new Intent(this, HelpActivity.class)); + return true; + } - load(); + return false; } private void refresh() { diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java index 6afe842b..7d303a8d 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java @@ -34,13 +34,12 @@ import android.os.Bundle; import android.os.Environment; import android.util.Log; import android.view.KeyEvent; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; import android.view.View; import android.view.Window; import android.widget.TextView; import github.daneren2005.dsub.R; +import com.actionbarsherlock.app.ActionBar; +import com.actionbarsherlock.app.SherlockActivity; import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.service.DownloadService; import github.daneren2005.dsub.service.DownloadServiceImpl; @@ -54,7 +53,7 @@ import github.daneren2005.dsub.util.Util; /** * @author Sindre Mehus */ -public class SubsonicTabActivity extends Activity { +public class SubsonicTabActivity extends SherlockActivity { private static final String TAG = SubsonicTabActivity.class.getSimpleName(); private static ImageLoader IMAGE_LOADER; @@ -68,9 +67,9 @@ public class SubsonicTabActivity extends Activity { @Override protected void onCreate(Bundle bundle) { setUncaughtExceptionHandler(); - applyTheme(); + // applyTheme(); super.onCreate(bundle); - requestWindowFeature(Window.FEATURE_NO_TITLE); + // requestWindowFeature(Window.FEATURE_NO_TITLE); startService(new Intent(this, DownloadServiceImpl.class)); setVolumeControlStream(AudioManager.STREAM_MUSIC); } @@ -78,6 +77,9 @@ public class SubsonicTabActivity extends Activity { @Override protected void onPostCreate(Bundle bundle) { super.onPostCreate(bundle); + + ActionBar actionBar = getSupportActionBar(); + // actionBar.setDisplayHomeAsUpEnabled(true); homeButton = findViewById(R.id.button_bar_home); homeButton.setOnClickListener(new View.OnClickListener() { @@ -136,36 +138,6 @@ public class SubsonicTabActivity extends Activity { Util.registerMediaButtonEventReceiver(this); } - @Override - public boolean onCreateOptionsMenu(Menu menu) { - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.main, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - - case R.id.menu_exit: - Intent intent = new Intent(this, MainActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - intent.putExtra(Constants.INTENT_EXTRA_NAME_EXIT, true); - Util.startActivityWithoutTransition(this, intent); - return true; - - case R.id.menu_settings: - startActivity(new Intent(this, SettingsActivity.class)); - return true; - - case R.id.menu_help: - startActivity(new Intent(this, HelpActivity.class)); - return true; - } - - return false; - } - @Override protected void onDestroy() { super.onDestroy(); @@ -194,23 +166,6 @@ public class SubsonicTabActivity extends Activity { Util.disablePendingTransition(this); } - @Override - public void setTitle(CharSequence title) { - super.setTitle(title); - - // Set the font of title in the action bar. - TextView text = (TextView) findViewById(R.id.actionbar_title_text); - Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/Storopia.ttf"); - text.setTypeface(typeface); - - text.setText(title); - } - - @Override - public void setTitle(int titleId) { - setTitle(getString(titleId)); - } - private void applyTheme() { String theme = Util.getTheme(this); if ("dark".equals(theme)) { -- cgit v1.2.3