Skip to content

Commit 33ee204

Browse files
author
Nilanchala
committed
added zip manager
added zip manager
1 parent be41345 commit 33ee204

File tree

11 files changed

+251
-0
lines changed

11 files changed

+251
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.zipp"
4+
android:versionCode="1"
5+
android:versionName="1.0">
6+
<uses-sdk android:minSdkVersion="8" />
7+
8+
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
9+
<activity android:name="MainActivity"
10+
android:label="@string/app_name">
11+
<intent-filter>
12+
<action android:name="android.intent.action.MAIN" />
13+
<category android:name="android.intent.category.LAUNCHER" />
14+
</intent-filter>
15+
</activity>
16+
17+
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
18+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
19+
</application>
20+
21+
22+
</manifest>
18 KB
Loading
23 KB
Loading
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This file is automatically generated by Android Tools.
2+
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3+
#
4+
# This file must be checked in Version Control Systems.
5+
#
6+
# To customize properties used by the Ant build system use,
7+
# "ant.properties", and override values to adapt the script to your
8+
# project structure.
9+
10+
# Project target.
11+
target=android-8
Loading
Loading
Loading
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="fill_parent"
4+
android:layout_height="fill_parent"
5+
android:orientation="vertical" >
6+
7+
<TextView
8+
android:layout_width="fill_parent"
9+
android:layout_height="wrap_content"
10+
android:gravity="center_horizontal"
11+
android:padding="10dp"
12+
android:text="@string/instruction"
13+
android:textAppearance="?android:attr/textAppearanceLarge" />
14+
15+
<Button
16+
android:id="@+id/button_zip"
17+
android:layout_width="match_parent"
18+
android:layout_height="wrap_content"
19+
android:padding="10dp"
20+
android:text="Create Zip" />
21+
22+
<Button
23+
android:id="@+id/button_unzip"
24+
android:layout_width="match_parent"
25+
android:layout_height="wrap_content"
26+
android:padding="10dp"
27+
android:text="Unzip" />
28+
29+
</LinearLayout>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<resources>
3+
<string name="instruction">Zipping and Unzipping!</string>
4+
<string name="app_name">User Application</string>
5+
</resources>
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package com.zipp;
2+
3+
import java.io.File;
4+
import java.io.FileInputStream;
5+
import java.io.FileNotFoundException;
6+
import java.io.FileOutputStream;
7+
import java.io.InputStream;
8+
import java.io.OutputStream;
9+
import android.app.Activity;
10+
import android.os.Bundle;
11+
import android.os.Environment;
12+
import android.util.Log;
13+
import android.view.View;
14+
import android.view.View.OnClickListener;
15+
import android.widget.Button;
16+
17+
public class MainActivity extends Activity {
18+
19+
String inputPath = Environment.getExternalStorageDirectory().getPath()+ "/ZipDemo/";
20+
String inputFile = "Apply.zip";
21+
String outputPath = Environment.getExternalStorageDirectory().getPath()+ "/UnZipDemo/";
22+
23+
@Override
24+
public void onCreate(Bundle savedInstanceState) {
25+
super.onCreate(savedInstanceState);
26+
setContentView(R.layout.main);
27+
28+
((Button) findViewById(R.id.button_zip))
29+
.setOnClickListener(new OnClickListener() {
30+
31+
@Override
32+
public void onClick(View view) {
33+
// declare an array for storing the files i.e the path
34+
// of your source files
35+
String[] s = new String[2];
36+
37+
// Type the path of the files in here
38+
s[0] = inputPath + "/image.jpg";
39+
s[1] = inputPath + "/textfile.txt"; // /sdcard/ZipDemo/textfile.txt
40+
41+
// first parameter is d files second parameter is zip
42+
// file name
43+
ZipManager zipManager = new ZipManager();
44+
45+
// calling the zip function
46+
zipManager.zip(s, inputPath + inputFile);
47+
}
48+
});
49+
50+
((Button) findViewById(R.id.button_unzip))
51+
.setOnClickListener(new OnClickListener() {
52+
53+
@Override
54+
public void onClick(View view) {
55+
ZipManager zipManager = new ZipManager();
56+
zipManager.unzip(inputPath + inputFile, outputPath);
57+
}
58+
});
59+
60+
//moveFile(inputPath, inputFile, outputPath);
61+
62+
}
63+
64+
private void moveFile(String inputPath, String inputFile, String outputPath) {
65+
66+
InputStream in = null;
67+
OutputStream out = null;
68+
try {
69+
// create output directory if it doesn't exist
70+
File dir = new File(outputPath);
71+
if (!dir.exists()) {
72+
dir.mkdirs();
73+
}
74+
75+
in = new FileInputStream(inputPath + inputFile);
76+
out = new FileOutputStream(outputPath + inputFile);
77+
78+
byte[] buffer = new byte[1024];
79+
int read;
80+
while ((read = in.read(buffer)) != -1) {
81+
out.write(buffer, 0, read);
82+
}
83+
in.close();
84+
in = null;
85+
86+
// write the output file
87+
out.flush();
88+
out.close();
89+
out = null;
90+
91+
// delete the original file
92+
new File(inputPath + inputFile).delete();
93+
}
94+
95+
catch (FileNotFoundException fnfe1) {
96+
Log.e("tag", fnfe1.getMessage());
97+
} catch (Exception e) {
98+
Log.e("tag", e.getMessage());
99+
}
100+
}
101+
}

0 commit comments

Comments
 (0)