Skip to content

Commit

Permalink
Started work on tabbed browsing. Updated demo app.
Browse files Browse the repository at this point in the history
  • Loading branch information
psaravan committed Sep 21, 2014
1 parent a8daf95 commit 811113b
Show file tree
Hide file tree
Showing 18 changed files with 358 additions and 8 deletions.
5 changes: 5 additions & 0 deletions demo-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
android:label="@string/app_name"
android:theme="@style/AppThemeLight" />

<activity
android:name=".TabbedBrowsingActivity.TabbedListActivity"
android:label="@string/app_name"
android:theme="@style/AppThemeLight" />

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.psaravan.filebrowserview.demo.GridActivity.GridActivity;
import com.psaravan.filebrowserview.demo.ListActivity.ListActivity;
import com.psaravan.filebrowserview.demo.R;
import com.psaravan.filebrowserview.demo.TabbedBrowsingActivity.TabbedListActivity;

/**
* Launcher class that displays all the options and FileBrowserView samples.
Expand Down Expand Up @@ -76,6 +77,8 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
fragment.show(fragmentManager, "dialogFragment");
break;
case 3:
intent = new Intent(mContext, TabbedListActivity.class);
startActivity(intent);
break;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright (C) 2014 Saravan Pantham
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.psaravan.filebrowserview.demo.TabbedBrowsingActivity;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;

import com.psaravan.filebrowserview.demo.R;
import com.psaravan.filebrowserview.lib.Interfaces.NavigationInterface;
import com.psaravan.filebrowserview.lib.View.FileBrowserView;

import java.io.File;

/**
* Example implementation for a tabbed, List representation of the view.
*
* @author Saravan Pantham
*/
public class TabbedListActivity extends Activity {

//Context.
private Context mContext;

//FileBrowserView reference.
private FileBrowserView mFileBrowserView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_file_browser_view);
mContext = this.getApplicationContext();

//Grab a reference handle on the view, just like you'd do with any other view.
mFileBrowserView = (FileBrowserView) findViewById(R.id.fileBrowserView);

//Customize the view.
mFileBrowserView.setFileBrowserLayoutType(FileBrowserView.FILE_BROWSER_LIST_LAYOUT) //Set the type of view to use.
.setDefaultDirectory(new File("/")) //Set the default directory to show.
.setShowHiddenFiles(true) //Set whether or not you want to show hidden files.
.showItemSizes(true) //Shows the sizes of each item in the list.
.showOverflowMenus(true) //Shows the overflow menus for each item in the list.
.showItemIcons(true) //Shows the icons next to each item name in the list.
.setNavigationInterface(navInterface) //Sets the nav interface instance for this view.
.enableTabbedBrowsing(true) //Enable tabbed browsing.
.init(); //Loads the view. You MUST call this method, or the view will not be displayed.

}

/**
* Navigation interface for the view. Used to capture events such as a new
* directory being loaded, files being opened, etc. For our purposes here,
* we'll be using the onNewDirLoaded() method to update the ActionBar's title
* with the current directory's path.
*/
private NavigationInterface navInterface = new NavigationInterface() {

@Override
public void onNewDirLoaded(File dirFile) {
//Update the action bar title.
getActionBar().setTitle(dirFile.getAbsolutePath());
}

@Override
public void onFileOpened(File file) {

}

@Override
public void onParentDirLoaded(File dirFile) {

}

@Override
public void onFileFolderOpenFailed(File file) {

}

};

}
2 changes: 1 addition & 1 deletion demo-app/src/main/res/values/array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<item>Simple List</item>
<item>Simple Grid</item>
<item>Dialog Fragment</item>
<item>Tabs</item>
<item>Tabbed Browsing</item>
<item>Custom Header View</item>
</string-array>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public GridLayoutView init() {
*
* @param directory The File object that points to the directory to load.
*/
private void showDir(File directory) {
@Override
protected void showDir(File directory) {

//Call the interface callback method.
if (mNavigationInterface!=null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public ListLayoutView(Context context, AttributeSet attributeSet, FileBrowserVie

/**
* Inflates the layout and sets the list's adapter.
*
* @return A reference to this view's instance.
*/
public ListLayoutView init() {
//Inflate the view from the XML resource.
Expand All @@ -67,7 +69,8 @@ public ListLayoutView init() {
*
* @param directory The File object that points to the directory to load.
*/
private void showDir(File directory) {
@Override
protected void showDir(File directory) {

//Call the interface callback method.
if (mNavigationInterface!=null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import com.psaravan.filebrowserview.lib.Interfaces.NavigationInterface;

import java.io.File;

/**
* The base layout that is extended by {@link com.psaravan.filebrowserview.lib.ListLayout.ListLayoutView}
* and {@link com.psaravan.filebrowserview.lib.GridLayout.GridLayoutView}.
Expand All @@ -30,6 +32,11 @@
*/
public abstract class BaseLayoutView extends View {

/**
* Context intstance.
*/
protected Context mContext;

/**
* The ListView/GridView that displays the file system.
*/
Expand All @@ -46,8 +53,17 @@ public abstract class BaseLayoutView extends View {
*/
public BaseLayoutView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
mContext = context;
}

/**
* Override this method to implement your logic for loading a directory structure of the
* specified dir and to set your AbsListView's adapter.
*
* @param directory The File object that points to the directory to load.
*/
protected abstract void showDir(File directory);

/**
* Sets the navigation interface instance for this view.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public class FileBrowserView extends FrameLayout {
//Navigation Interface.
private NavigationInterface mNavigationInterface;

//Whether or not tabbed browsing is enabled.
private boolean mTabbedBrowsingEnabled = false;

public FileBrowserView(Context context) {
super(context);
mContext = context;
Expand Down Expand Up @@ -112,11 +115,20 @@ public void init() {
//Initialize the file browser engine for this view instance.
mFileBrowserEngine = new FileBrowserEngine(mContext, this);

//Inflate the view's layout based on the selected layout.
if (getFileBrowserLayoutType()==FILE_BROWSER_LIST_LAYOUT)
mFileBrowserLayout = new ListLayoutView(mContext, mAttributeSet, this).init();
else
mFileBrowserLayout = new GridLayoutView(mContext, mAttributeSet, this).init();
/*
* If tabbed browsing is enabled, an instance of TabContainer will
* become the direct child of this view. If not, we can directly
* inflate the List/Grid layout views.
*/
if (isTabbedBrowsingEnabled()) {
mFileBrowserLayout = new TabsContainer(mContext, mAttributeSet, this).init();
} else {
//Inflate the view's layout based on the selected layout.
if (getFileBrowserLayoutType()==FILE_BROWSER_LIST_LAYOUT)
mFileBrowserLayout = new ListLayoutView(mContext, mAttributeSet, this).init();
else
mFileBrowserLayout = new GridLayoutView(mContext, mAttributeSet, this).init();
}

//Apply the navigation interface.
mFileBrowserLayout.setNavigationInterface(mNavigationInterface);
Expand Down Expand Up @@ -245,6 +257,26 @@ public FileBrowserView setNavigationInterface(NavigationInterface navInterface)
return this;
}

/**
* Sets whether or not tabbed browsing should be enabled. If you pass true,
* a TabHost will be placed above the FileBrowserView and will allow the user
* to open new tabs to browse the filesystem (à la Google Chrome tab browsing).
*
* @param enable Whether or not tabbed browsing should be enabled.
* @return An instance of this FileBrowserView to allow method chaining.
*/
public FileBrowserView enableTabbedBrowsing(boolean enable) {
mTabbedBrowsingEnabled = enable;
return this;
}

/**
* @return The AttributeSet object associated with this view instance.
*/
public AttributeSet getAttributeSet() {
return mAttributeSet;
}

/**
* @return The current layout type for this FileBrowserView instance.
*/
Expand Down Expand Up @@ -319,4 +351,11 @@ public boolean shouldShowItemIcons() {

}

/**
* @return Whether tabbed browsing is enabled or not for this FileBrowserView instance.
*/
public boolean isTabbedBrowsingEnabled() {
return mTabbedBrowsingEnabled;
}

}
Loading

0 comments on commit 811113b

Please sign in to comment.