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