e9714c71623c31ad1f195c9a2099d4bb8cb621f3
[pub/Android/ownCloud.git] / src / eu / alefzero / owncloud / ui / fragment / PathLayout.java
1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18 package eu.alefzero.owncloud.ui.fragment;
19
20 import java.util.LinkedList;
21 import java.util.Stack;
22
23 import eu.alefzero.owncloud.R;
24 import eu.alefzero.owncloud.R.drawable;
25
26 import android.content.Context;
27 import android.util.AttributeSet;
28 import android.widget.HorizontalScrollView;
29 import android.widget.ImageView;
30 import android.widget.LinearLayout;
31 import android.widget.ScrollView;
32 import android.widget.TextView;
33
34 /**
35 * Part of the ActionBar Layout
36 * @author Bartek Przybylski
37 *
38 */
39 public class PathLayout extends LinearLayout {
40
41 private LinkedList<String> paths;
42 ScrollView internalScroll;
43 LinearLayout view;
44
45 public PathLayout(Context context) {
46 super(context);
47 initialize();
48 }
49
50 public PathLayout(Context context, AttributeSet attrs) {
51 super(context, attrs);
52 initialize();
53 }
54
55 public String pop() {
56 if (paths.size() == 0) {
57 return null;
58 }
59 int start = paths.size()*2-2;
60 int count = 2;
61 if (paths.size() == 1) {
62 start++;
63 count--;
64 }
65 view.removeViews(start, count);
66 return paths.removeLast();
67 }
68
69 public void addPath(String path) {
70 for (String s : path.split("/")) if (s.length() != 0) push(s);
71 }
72
73 public void push(String path) {
74 // its weird that we cannot declare static imgView as path separator
75 if (paths.size() != 0) {
76 ImageView iv = new ImageView(getContext());
77 iv.setImageDrawable(getResources().getDrawable(R.drawable.breadcrumb));
78 iv.setPadding(2, 0, 2, 0);
79 view.addView(iv);
80 }
81 TextView tv = new TextView(getContext());
82 tv.setLayoutParams(getLayoutParams());
83 tv.setText(path);
84 view.addView(tv);
85 HorizontalScrollView hsv = (HorizontalScrollView) internalScroll.getChildAt(0);
86 hsv.smoothScrollTo(hsv.getMaxScrollAmount()*2, 0);
87 paths.addLast(path);
88 }
89
90 public String peek() {
91 return paths.peek();
92 }
93
94 public String getFullPath() {
95 String ret = new String();
96 for (int i = 0; i < paths.size(); i++) {
97 ret += "/" + paths.get(i);
98 }
99 return ret;
100 }
101
102 private void initialize() {
103 paths = new LinkedList<String>();
104 internalScroll = new ScrollView(getContext());
105 internalScroll.setFillViewport(true);
106 HorizontalScrollView hsv = new HorizontalScrollView(getContext());
107 hsv.setSmoothScrollingEnabled(true);
108 internalScroll.addView(hsv);
109 view = new LinearLayout(getContext());
110 addView(internalScroll);
111 hsv.addView(view);
112 ImageView iv = new ImageView(getContext());
113 iv.setImageDrawable(getResources().getDrawable(R.drawable.breadcrumb));
114 view.addView(iv);
115 }
116
117 }