diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-05-11 12:58:50 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-05-11 12:58:50 -0700 |
commit | 51c86acd2035f021f4312903ec6a48876749a31a (patch) | |
tree | 5ab3712f0f1a9de24996ee5ab8da906453f0d2e8 /subsonic-android | |
parent | 6eb0cfca6d498082e90ef2a080b87772ab33fdbe (diff) | |
download | dsub-51c86acd2035f021f4312903ec6a48876749a31a.tar.gz dsub-51c86acd2035f021f4312903ec6a48876749a31a.tar.bz2 dsub-51c86acd2035f021f4312903ec6a48876749a31a.zip |
Added breadbrumb trail when going down in fragments
Diffstat (limited to 'subsonic-android')
3 files changed, 120 insertions, 16 deletions
diff --git a/subsonic-android/res/layout/actionbar_spinner.xml b/subsonic-android/res/layout/actionbar_spinner.xml new file mode 100644 index 00000000..22055901 --- /dev/null +++ b/subsonic-android/res/layout/actionbar_spinner.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8"?> +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:gravity="fill_horizontal" > + <Spinner + android:id="@+id/spinner" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:prompt="@string/common.appname" + /> +</RelativeLayout> diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java index 4e116266..a0836941 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -14,6 +14,11 @@ import android.support.v4.app.FragmentTransaction; import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.KeyEvent;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemSelectedListener;
+import android.widget.ArrayAdapter;
+import android.widget.Spinner;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.app.ActionBar.TabListener;
@@ -34,7 +39,7 @@ import java.io.PrintWriter; import java.util.ArrayList;
import java.util.List;
-public class SubsonicActivity extends SherlockFragmentActivity {
+public class SubsonicActivity extends SherlockFragmentActivity implements OnItemSelectedListener {
private static final String TAG = SubsonicActivity.class.getSimpleName();
private static ImageLoader IMAGE_LOADER;
protected static String theme;
@@ -45,6 +50,8 @@ public class SubsonicActivity extends SherlockFragmentActivity { protected List<Integer> backStackId = new ArrayList<Integer>();
protected SubsonicFragment currentFragment;
protected int currentFragmentId;
+ Spinner actionBarSpinner;
+ ArrayAdapter<CharSequence> spinnerAdapter;
@Override
protected void onCreate(Bundle bundle) {
@@ -54,6 +61,20 @@ public class SubsonicActivity extends SherlockFragmentActivity { startService(new Intent(this, DownloadServiceImpl.class));
setVolumeControlStream(AudioManager.STREAM_MUSIC);
}
+
+ @Override
+ protected void onPostCreate(Bundle bundle) {
+ super.onPostCreate(bundle);
+
+ View actionbar = getLayoutInflater().inflate(R.layout.actionbar_spinner, null);
+ actionBarSpinner = (Spinner)actionbar.findViewById(R.id.spinner);
+ spinnerAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item);
+ spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ actionBarSpinner.setOnItemSelectedListener(this);
+ actionBarSpinner.setAdapter(spinnerAdapter);
+
+ getSupportActionBar().setCustomView(actionbar);
+ }
@Override
protected void onResume() {
@@ -147,24 +168,40 @@ public class SubsonicActivity extends SherlockFragmentActivity { return super.onKeyDown(keyCode, event);
}
+ @Override
+ public void setTitle(CharSequence title) {
+ if(pagerAdapter != null) {
+ pagerAdapter.recreateSpinner();
+ } else {
+ recreateSpinner();
+ }
+ }
+
+ @Override
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+ int top = spinnerAdapter.getCount() - 1;
+ if(position < top) {
+ for(int i = top; i > position; i--) {
+ if(pagerAdapter != null) {
+ pagerAdapter.removeCurrent();
+ } else {
+ removeCurrent();
+ }
+ }
+ }
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView<?> parent) {
+
+ }
+
public boolean onBackPressedSupport() {
if(pagerAdapter != null) {
return pagerAdapter.onBackPressed();
} else {
if(backStack.size() > 0) {
- if(currentFragment != null) {
- currentFragment.setPrimaryFragment(false);
- }
- Fragment oldFrag = (Fragment)currentFragment;
-
- currentFragment = (SubsonicFragment) backStack.remove(backStack.size() - 1);
- currentFragmentId = backStackId.remove(backStackId.size() - 1);
- currentFragment.setPrimaryFragment(true);
- invalidateOptionsMenu();
-
- FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
- trans.remove(oldFrag);
- trans.commit();
+ removeCurrent();
return false;
} else {
return true;
@@ -190,6 +227,38 @@ public class SubsonicActivity extends SherlockFragmentActivity { FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
trans.add(id, fragment);
trans.commit();
+ recreateSpinner();
+ }
+ }
+ private void removeCurrent() {
+ if(currentFragment != null) {
+ currentFragment.setPrimaryFragment(false);
+ }
+ Fragment oldFrag = (Fragment)currentFragment;
+
+ currentFragment = (SubsonicFragment) backStack.remove(backStack.size() - 1);
+ currentFragmentId = backStackId.remove(backStackId.size() - 1);
+ currentFragment.setPrimaryFragment(true);
+ invalidateOptionsMenu();
+
+ FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
+ trans.remove(oldFrag);
+ trans.commit();
+ recreateSpinner();
+ }
+
+ private void recreateSpinner() {
+ if(backStack.size() > 0) {
+ spinnerAdapter.clear();
+ for(int i = 0; i < backStack.size(); i++) {
+ spinnerAdapter.add(backStack.get(i).getTitle());
+ }
+ spinnerAdapter.add(currentFragment.getTitle());
+ spinnerAdapter.notifyDataSetChanged();
+ actionBarSpinner.setSelection(spinnerAdapter.getCount() - 1);
+ getSupportActionBar().setDisplayShowCustomEnabled(true);
+ } else {
+ getSupportActionBar().setDisplayShowCustomEnabled(false);
}
}
@@ -406,6 +475,7 @@ public class SubsonicActivity extends SherlockFragmentActivity { currentFragment.setPrimaryFragment(true);
}
activity.invalidateOptionsMenu();
+ recreateSpinner();
}
public void addTab(CharSequence title, Class fragmentClass, Bundle args) {
@@ -436,6 +506,7 @@ public class SubsonicActivity extends SherlockFragmentActivity { FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
trans.add(id, fragment);
trans.commit();
+ recreateSpinner();
}
public void removeCurrent() {
@@ -458,6 +529,7 @@ public class SubsonicActivity extends SherlockFragmentActivity { List fragStack = (List)frags.get(currentPosition);
if(fragStack.size() > 1) {
removeCurrent();
+ recreateSpinner();
return false;
} else {
if(currentPosition == 0) {
@@ -469,6 +541,22 @@ public class SubsonicActivity extends SherlockFragmentActivity { }
}
+ private void recreateSpinner() {
+ List fragStack = (List)frags.get(currentPosition);
+ if(fragStack.size() > 1) {
+ spinnerAdapter.clear();
+ for(int i = 0; i < fragStack.size(); i++) {
+ SubsonicFragment frag = (SubsonicFragment)fragStack.get(i);
+ spinnerAdapter.add(frag.getTitle());
+ }
+ spinnerAdapter.notifyDataSetChanged();
+ actionBarSpinner.setSelection(spinnerAdapter.getCount() - 1);
+ actionBar.setDisplayShowCustomEnabled(true);
+ } else {
+ actionBar.setDisplayShowCustomEnabled(false);
+ }
+ }
+
public void invalidate() {
for (int i = 0; i < frags.size(); i++) {
List fragStack = (List)frags.get(i);
diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 46e4f8c4..3d938dc9 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -329,14 +329,17 @@ public class SubsonicFragment extends SherlockFragment { return SubsonicActivity.getStaticImageLoader(context);
}
- protected void setTitle(CharSequence title) {
+ public void setTitle(CharSequence title) {
this.title = title;
context.setTitle(title);
}
- protected void setTitle(int title) {
+ public void setTitle(int title) {
this.title = context.getResources().getString(title);
context.setTitle(this.title);
}
+ public CharSequence getTitle() {
+ return this.title;
+ }
protected void warnIfNetworkOrStorageUnavailable() {
if (!Util.isExternalStoragePresent()) {
|