diff --git a/app/src/main/java/com/simplemobiletools/filemanager/Breadcrumbs.java b/app/src/main/java/com/simplemobiletools/filemanager/Breadcrumbs.java new file mode 100644 index 00000000..6816deae --- /dev/null +++ b/app/src/main/java/com/simplemobiletools/filemanager/Breadcrumbs.java @@ -0,0 +1,107 @@ +package com.simplemobiletools.filemanager; + +import android.content.Context; +import android.graphics.Point; +import android.util.AttributeSet; +import android.view.Display; +import android.view.LayoutInflater; +import android.view.View; +import android.view.WindowManager; +import android.widget.LinearLayout; +import android.widget.TextView; + +public class Breadcrumbs extends LinearLayout { + private LayoutInflater mInflater; + private int mDeviceWidth; + + public Breadcrumbs(Context context, AttributeSet attrs) { + super(context, attrs); + init(context); + } + + private void init(Context context) { + mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + final Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); + final Point deviceDisplay = new Point(); + display.getSize(deviceDisplay); + mDeviceWidth = deviceDisplay.x; + } + + @Override + protected void onLayout(boolean changed, int l, int t, int r, int b) { + final int paddingTop = getPaddingTop(); + final int paddingLeft = getPaddingLeft(); + final int childRight = getMeasuredWidth() - getPaddingRight(); + final int childBottom = getMeasuredHeight() - getPaddingBottom(); + final int childHeight = childBottom - paddingTop; + + final int usableWidth = mDeviceWidth - paddingLeft - getPaddingRight(); + int maxHeight = 0; + int curWidth; + int curHeight; + int curLeft = paddingLeft; + int curTop = paddingTop; + + final int cnt = getChildCount(); + for (int i = 0; i < cnt; i++) { + final View child = getChildAt(i); + + child.measure(MeasureSpec.makeMeasureSpec(usableWidth, MeasureSpec.AT_MOST), + MeasureSpec.makeMeasureSpec(childHeight, MeasureSpec.AT_MOST)); + curWidth = child.getMeasuredWidth(); + curHeight = child.getMeasuredHeight(); + + if (curLeft + curWidth >= childRight) { + curLeft = paddingLeft; + curTop += maxHeight; + maxHeight = 0; + } + + child.layout(curLeft, curTop, curLeft + curWidth, curTop + curHeight); + if (maxHeight < curHeight) + maxHeight = curHeight; + + curLeft += curWidth; + } + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + final int usableWidth = mDeviceWidth - getPaddingLeft() - getPaddingRight(); + int width = 0; + int rowHeight = 0; + int lines = 1; + + final int cnt = getChildCount(); + for (int i = 0; i < cnt; i++) { + final View child = getChildAt(i); + measureChild(child, widthMeasureSpec, heightMeasureSpec); + width += child.getMeasuredWidth(); + rowHeight = child.getMeasuredHeight(); + + if (width / usableWidth > 0) { + lines++; + width = child.getMeasuredWidth(); + } + } + + final int parentWidth = MeasureSpec.getSize(widthMeasureSpec); + final int calculatedHeight = getPaddingTop() + getPaddingBottom() + (rowHeight * lines); + setMeasuredDimension(parentWidth, calculatedHeight); + } + + public void setInitialBreadcrumb() { + addBreadcrumb("home"); + } + + public void addBreadcrumb(String text) { + final View view = mInflater.inflate(R.layout.breadcrumb_item, null, false); + final TextView textView = (TextView) view.findViewById(R.id.breadcrumb_text); + textView.setText(text); + addView(view); + } + + public void removeBreadcrumb() { + removeView(getChildAt(getChildCount() - 1)); + } +} diff --git a/app/src/main/java/com/simplemobiletools/filemanager/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/filemanager/activities/MainActivity.java index b4268591..2be4b366 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/activities/MainActivity.java @@ -6,20 +6,24 @@ import android.content.pm.PackageManager; import android.os.Bundle; import android.os.Environment; import android.support.v4.app.ActivityCompat; -import android.support.v4.app.FragmentManager; import android.support.v7.app.AppCompatActivity; import android.view.Menu; import android.view.MenuItem; +import com.simplemobiletools.filemanager.Breadcrumbs; import com.simplemobiletools.filemanager.Config; import com.simplemobiletools.filemanager.Constants; import com.simplemobiletools.filemanager.R; import com.simplemobiletools.filemanager.Utils; import com.simplemobiletools.filemanager.fragments.ItemsFragment; +import com.simplemobiletools.filemanager.models.FileDirItem; +import butterknife.BindView; import butterknife.ButterKnife; public class MainActivity extends AppCompatActivity implements ItemsFragment.ItemInteractionListener { + @BindView(R.id.breadcrumbs) Breadcrumbs mBreadcrumbs; + private static final int STORAGE_PERMISSION = 1; @Override @@ -47,13 +51,12 @@ public class MainActivity extends AppCompatActivity implements ItemsFragment.Ite private void initRootFileManager() { final String path = Environment.getExternalStorageDirectory().toString(); openPath(path); + mBreadcrumbs.setInitialBreadcrumb(); } private void openPath(String path) { final Bundle bundle = new Bundle(); bundle.putString(Constants.PATH, path); - if (getSupportFragmentManager().getBackStackEntryCount() > 0) - setTitle(path); final ItemsFragment fragment = new ItemsFragment(); fragment.setArguments(bundle); @@ -81,16 +84,11 @@ public class MainActivity extends AppCompatActivity implements ItemsFragment.Ite @Override public void onBackPressed() { - final FragmentManager manager = getSupportFragmentManager(); - final int cnt = manager.getBackStackEntryCount(); + final int cnt = getSupportFragmentManager().getBackStackEntryCount(); if (cnt == 1) finish(); else { - if (cnt == 2) { - setTitle(getResources().getString(R.string.app_name)); - } else { - setTitle(manager.getBackStackEntryAt(cnt - 2).getName()); - } + mBreadcrumbs.removeBreadcrumb(); super.onBackPressed(); } } @@ -110,7 +108,8 @@ public class MainActivity extends AppCompatActivity implements ItemsFragment.Ite } @Override - public void itemClicked(String path) { - openPath(path); + public void itemClicked(FileDirItem item) { + openPath(item.getPath()); + mBreadcrumbs.addBreadcrumb(" -> " + item.getName()); } } diff --git a/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java b/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java index 0e9012f1..b4883677 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java @@ -163,7 +163,7 @@ public class ItemsFragment extends android.support.v4.app.Fragment final FileDirItem item = mItems.get(position); if (item.getIsDirectory()) { if (mListener != null) - mListener.itemClicked(item.getPath()); + mListener.itemClicked(item); } else { final String path = item.getPath(); final File file = new File(path); @@ -588,6 +588,6 @@ public class ItemsFragment extends android.support.v4.app.Fragment } public interface ItemInteractionListener { - void itemClicked(String path); + void itemClicked(FileDirItem item); } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index a1407913..343e16af 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,6 +1,21 @@ - + android:layout_height="match_parent"> + + + + + + diff --git a/app/src/main/res/layout/breadcrumb_item.xml b/app/src/main/res/layout/breadcrumb_item.xml new file mode 100644 index 00000000..221d40a1 --- /dev/null +++ b/app/src/main/res/layout/breadcrumb_item.xml @@ -0,0 +1,6 @@ + +