9d6e751657a2ce8b31acd111ad9da37ec44b4075
[pub/Android/ownCloud.git] / src / eu / alefzero / owncloud / PathLayout.java
1 package eu.alefzero.owncloud;
2
3 import java.util.Stack;
4
5 import android.content.Context;
6 import android.util.AttributeSet;
7 import android.widget.HorizontalScrollView;
8 import android.widget.ImageView;
9 import android.widget.LinearLayout;
10 import android.widget.ScrollView;
11 import android.widget.TextView;
12
13 public class PathLayout extends LinearLayout {
14
15 private Stack<String> paths;
16 ScrollView internalScroll;
17 LinearLayout view;
18
19 public PathLayout(Context context) {
20 super(context);
21 initialize();
22 }
23
24 public PathLayout(Context context, AttributeSet attrs) {
25 super(context, attrs);
26 initialize();
27 }
28
29 public String pop() {
30 if (paths.empty()) {
31 return null;
32 }
33 int start = paths.size()*2-2;
34 int count = 2;
35 if (paths.size() == 1) {
36 start++;
37 count--;
38 }
39 view.removeViews(start, count);
40 return paths.pop();
41 }
42
43 public void push(String path) {
44 // its weird that we cannot declare static imgView as path separator
45 if (!paths.empty()) {
46 ImageView iv = new ImageView(getContext());
47 iv.setImageDrawable(getResources().getDrawable(R.drawable.breadcrumb));
48 iv.setPadding(2, 0, 2, 0);
49 view.addView(iv);
50 }
51 TextView tv = new TextView(getContext());
52 tv.setLayoutParams(getLayoutParams());
53 tv.setText(path);
54 view.addView(tv);
55 HorizontalScrollView hsv = (HorizontalScrollView) internalScroll.getChildAt(0);
56 hsv.smoothScrollTo(hsv.getMaxScrollAmount()*2, 0);
57 paths.push(path);
58 }
59
60 public String peek() {
61 return paths.peek();
62 }
63
64 private void initialize() {
65 paths = new Stack<String>();
66 internalScroll = new ScrollView(getContext());
67 internalScroll.setFillViewport(true);
68 HorizontalScrollView hsv = new HorizontalScrollView(getContext());
69 hsv.setSmoothScrollingEnabled(true);
70 internalScroll.addView(hsv);
71 view = new LinearLayout(getContext());
72 addView(internalScroll);
73 hsv.addView(view);
74 ImageView iv = new ImageView(getContext());
75 iv.setImageDrawable(getResources().getDrawable(R.drawable.breadcrumb));
76 view.addView(iv);
77 }
78
79 }