Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
acraig5075 committed May 24, 2012
0 parents commit 0420bc6
Show file tree
Hide file tree
Showing 8 changed files with 599 additions and 0 deletions.
20 changes: 20 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.za.acraig.movefiles"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>

<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MoveFilesActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="QuickPrefsActivity"></activity>

</application>
</manifest>
140 changes: 140 additions & 0 deletions res/layout/main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" -->
<!-- android:id="@+id/linearLayout" -->
<!-- android:orientation="vertical" -->
<!-- android:layout_width="fill_parent" -->
<!-- android:layout_height="fill_parent" -->
<!-- > -->
<!-- <TextView -->
<!-- android:id="@+id/src" -->
<!-- android:layout_width="fill_parent" -->
<!-- android:layout_height="wrap_content" -->
<!-- /> -->
<!-- <TextView -->
<!-- android:id="@+id/srccount" -->
<!-- android:layout_width="fill_parent" -->
<!-- android:layout_height="wrap_content" -->
<!-- /> -->
<!-- <TextView -->
<!-- android:id="@+id/dest" -->
<!-- android:layout_width="fill_parent" -->
<!-- android:layout_height="wrap_content" -->
<!-- /> -->
<!-- <TextView -->
<!-- android:id="@+id/destcount" -->
<!-- android:layout_width="fill_parent" -->
<!-- android:layout_height="wrap_content" -->
<!-- /> -->
<!-- <CheckBox -->
<!-- android:id="@+id/deleteBefore" -->
<!-- android:text="Clear dest directory before the copy" -->
<!-- android:layout_width="wrap_content" -->
<!-- android:layout_height="wrap_content" -->
<!-- android:checked="false" -->
<!-- android:enabled="false" -->
<!-- /> -->
<!-- <CheckBox -->
<!-- android:id="@+id/deleteAfter" -->
<!-- android:text="Delete src files after the copy" -->
<!-- android:layout_width="wrap_content" -->
<!-- android:layout_height="wrap_content" -->
<!-- android:checked="false" -->
<!-- android:enabled="false" -->
<!-- /> -->
<!-- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" -->
<!-- android:id="@+id/linearLayout" -->
<!-- android:orientation="horizontal" -->
<!-- android:layout_width="fill_parent" -->
<!-- android:layout_height="wrap_content" -->
<!-- > -->
<!-- <Button -->
<!-- android:text="Copy files" -->
<!-- android:id="@+id/copyButton" -->
<!-- android:layout_width="wrap_content" -->
<!-- android:layout_height="wrap_content" -->
<!-- android:enabled="false" -->
<!-- android:onClick="onCopyClick" -->
<!-- /> -->
<!-- <Button -->
<!-- android:text="Swap Src/Dest" -->
<!-- android:id="@+id/swapButton" -->
<!-- android:layout_width="wrap_content" -->
<!-- android:layout_height="wrap_content" -->
<!-- android:enabled="true" -->
<!-- android:onClick="onSwapClick" -->
<!-- /> -->
<!-- </LinearLayout> -->
<!-- </LinearLayout> -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout2"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:baselineAligned="true">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout3"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/src"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/srccount"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/dest"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/destcount"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<Button
android:text="Swap"
android:id="@+id/swapButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="true"
android:onClick="onSwapClick"
android:layout_gravity="center_vertical"/>
</LinearLayout>
<CheckBox
android:id="@+id/deleteBefore"
android:text="Clear dest directory before the copy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:enabled="false"
/>
<CheckBox
android:id="@+id/deleteAfter"
android:text="Delete src files after the copy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:enabled="false"
/>
<Button
android:text="Copy files"
android:id="@+id/copyButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="false"
android:onClick="onCopyClick"
android:layout_gravity="center_horizontal"
/>
</LinearLayout>
89 changes: 89 additions & 0 deletions src/net/za/acraig/movefiles/CopyVisitor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package net.za.acraig.movefiles;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class CopyVisitor extends Visitor
{
private File _destDir;
private boolean _move = false; // whether to move files or copy them
private String _result = "Podcasts listened to this week:\n"; // concatenation of copied filenames

public CopyVisitor(File dest)
{
_destDir = dest;
}

public void setMoveMode(boolean move)
{
_move = move;
}

protected void processFile(final File file)
{
// Thread copyThread = new Thread()
// {
// public void run()
// {
// copyFile(file);
// if (_move)
// file.delete();
// }
// };
// copyThread.start();

boolean copyOk = copyFile(file);

if (copyOk)
_result += file.getName() + "\n";
if (copyOk && _move)
file.delete();
}

private boolean copyFile(File file)
{
try
{
String destname = _destDir.getAbsolutePath() + File.separator + file.getName();
File dest = new File(destname);
if (dest.exists())
return false;

InputStream in = new FileInputStream(file);
OutputStream out = new FileOutputStream(dest);

byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0)
{
out.write(buf, 0, len);
}
in.close();
out.close();

boolean succesfulCopy = (file.length() == dest.length());
return succesfulCopy;
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}

public String getResult()
{
return _result;
}
}
18 changes: 18 additions & 0 deletions src/net/za/acraig/movefiles/CountVisitor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.za.acraig.movefiles;

import java.io.File;

public class CountVisitor extends Visitor
{
private int _count = 0;

protected void processFile(File file)
{
_count++;
}

public final int getCount()
{
return _count;
}
}
23 changes: 23 additions & 0 deletions src/net/za/acraig/movefiles/DeleteVisitor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package net.za.acraig.movefiles;

import java.io.File;

public class DeleteVisitor extends Visitor
{
public DeleteVisitor()
{
}

@Override
protected void processEmptyDir(File d)
{
d.delete();
}

@Override
protected void processFile(File f)
{
f.delete();
}

}
Loading

0 comments on commit 0420bc6

Please sign in to comment.