Skip to content

Commit

Permalink
almost finish the compression.
Browse files Browse the repository at this point in the history
  • Loading branch information
hzy3774 committed Oct 20, 2014
1 parent 2c595f3 commit a1efe64
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 56 deletions.
51 changes: 15 additions & 36 deletions MyZipTest/res/layout/activity_compress.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/buttonCoSrc"
android:ems="10"
android:hint="Source files"
android:hint="Source files/Wildcard"
android:singleLine="true" >

<requestFocus />
Expand Down Expand Up @@ -52,60 +52,39 @@
android:layout_below="@+id/buttonCoSrc"
android:text="..." />

<EditText
android:id="@+id/editTextCoAchieveName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/buttonCoDstPath"
android:ems="10"
android:hint="Achieve name"
android:singleLine="true" />

<TextView
android:id="@+id/textViewCoType"
<CheckBox
android:id="@+id/checkBoxCoType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/editTextCoAchieveName"
android:text="Type of archive:"
android:textAppearance="?android:attr/textAppearanceMedium" />
android:layout_below="@+id/editTextCoDstPath"
android:text="Specify type" />

<Spinner
android:id="@+id/spinnerCoType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editTextCoAchieveName"
android:layout_toRightOf="@+id/textViewCoType"
android:layout_below="@+id/editTextCoDstPath"
android:layout_toRightOf="@+id/checkBoxCoType"
android:visibility="invisible"
android:entries="@array/array_compress_type" />

<CheckBox
android:id="@+id/checkBoxCoWildcard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/spinnerCoType"
android:checked="false"
android:text="Wildcard/File name" />

<EditText
android:id="@+id/editTextCoWildcard"
android:layout_width="wrap_content"
android:id="@+id/editTextCoAchieveName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/checkBoxCoWildcard"
android:layout_below="@+id/spinnerCoType"
android:ems="10"
android:hint="Enter a wildcard"
android:singleLine="true"
android:visibility="gone" />
android:hint="Achieve name"
android:singleLine="true" />

<CheckBox
android:id="@+id/checkBoxCoPasswd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/editTextCoWildcard"
android:layout_below="@+id/editTextCoAchieveName"
android:checked="false"
android:text="Password" />

Expand All @@ -114,7 +93,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/editTextCoWildcard"
android:layout_below="@+id/editTextCoAchieveName"
android:text="ShowPassword"
android:visibility="gone" />

Expand Down
33 changes: 18 additions & 15 deletions MyZipTest/src/com/example/myziptest/CompressActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@

public class CompressActivity extends Activity{

EditText etSrc, etDst, etFileName, etWildcard, etPassword;
EditText etSrc, etDst, etFileName, etPassword;
Button btSrc, btDst, btExecute;
CheckBox cbWildcard, cbPassword, cbShowPwd;
CheckBox cbPassword, cbShowPwd, cbType;
Spinner spType;
OnClickListener btClickListener;
OnCheckedChangeListener onCheckboxListener;

boolean isWildcard = false;
boolean isPassword = false;
boolean isSpecifyType = false;

String[] fileTypes;

Expand All @@ -44,16 +44,15 @@ protected void onCreate(Bundle savedInstanceState) {
etSrc = (EditText) findViewById(id.editTextCoSrc);
etDst = (EditText) findViewById(id.editTextCoDstPath);
etFileName = (EditText) findViewById(id.editTextCoAchieveName);
etWildcard = (EditText) findViewById(id.editTextCoWildcard);
etPassword = (EditText) findViewById(id.editTextCoPasswd);
//button
btSrc = (Button) findViewById(id.buttonCoSrc);
btDst = (Button) findViewById(id.buttonCoDstPath);
btExecute = (Button) findViewById(id.buttonCoExecute);
//checkbox
cbWildcard = (CheckBox) findViewById(id.checkBoxCoWildcard);
cbPassword = (CheckBox) findViewById(id.checkBoxCoPasswd);
cbShowPwd = (CheckBox) findViewById(id.checkBoxCoPwdVisible);
cbType = (CheckBox) findViewById(id.checkBoxCoType);
//spinner
spType = (Spinner) findViewById(id.spinnerCoType);
fileTypes = getResources().getStringArray(array.array_compress_type);
Expand All @@ -66,7 +65,7 @@ public void onClick(View v) {
case id.buttonCoSrc:
startFileChooser(FileChooseActivity.FILTER_DIR |
FileChooseActivity.FILTER_FILE | FileChooseActivity.FILTER_MULTI,
REQUEST_CODE_DST);
REQUEST_CODE_SRC);
break;
case id.buttonCoDstPath:
startFileChooser(FileChooseActivity.FILTER_DIR, REQUEST_CODE_DST);
Expand All @@ -85,11 +84,6 @@ public void onClick(View v) {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
switch (buttonView.getId()) {
case id.checkBoxCoWildcard:
etWildcard.setVisibility(isChecked ? View.VISIBLE : View.GONE);
etWildcard.requestFocus();
isWildcard = isChecked;
break;
case id.checkBoxCoPasswd:
etPassword.setVisibility(isChecked ? View.VISIBLE : View.GONE);
etPassword.requestFocus();
Expand All @@ -102,6 +96,10 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
etPassword.setInputType(pwdType);
etPassword.selectAll();
break;
case id.checkBoxCoType:
isSpecifyType = isChecked;
spType.setVisibility(isChecked ? View.VISIBLE : View.INVISIBLE);
break;
default:
break;
}
Expand All @@ -113,9 +111,9 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
btDst.setOnClickListener(btClickListener);
btExecute.setOnClickListener(btClickListener);

cbWildcard.setOnCheckedChangeListener(onCheckboxListener);
cbPassword.setOnCheckedChangeListener(onCheckboxListener);
cbShowPwd.setOnCheckedChangeListener(onCheckboxListener);
cbType.setOnCheckedChangeListener(onCheckboxListener);
}

//open a file choose activity to choose file
Expand All @@ -127,9 +125,14 @@ private void startFileChooser(int filter, int requestCode){

private void compressProcess(){
StringBuilder sbCmd = new StringBuilder("7z a ");
sbCmd.append("-t" + fileTypes[spType.getSelectedItemPosition()] + " "); //7z a -t7z
sbCmd.append("'" + etDst.getText() + File.separator + etFileName.getText() + "' "); //7z a -t7z '/hh.7z'

if(isSpecifyType){
sbCmd.append("-t" + fileTypes[spType.getSelectedItemPosition()] + " "); //7z a -t7z
}
sbCmd.append("'" + etDst.getText() + File.separator + etFileName.getText() + "' "); //7z a '/hh.7z'
sbCmd.append("'" + etSrc.getText() + "' "); //7z a '/hh.7z' '/paths'
if(isPassword){
sbCmd.append("'-p" + etPassword.getText().toString() + "' ");
}
new ZipProcess(CompressActivity.this, sbCmd.toString()).start();
}

Expand Down
24 changes: 19 additions & 5 deletions MyZipTest/src/com/example/myziptest/FileChooseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
Expand Down Expand Up @@ -116,15 +117,28 @@ public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case id.buttonFcDone:
Intent intent = new Intent();
String retStr = null;
if(chooseMulti){

//return selected paths/files
StringBuilder sbStr = new StringBuilder("");
List<Boolean> flags = adapter.getCheckedIndexList();
for(int i = 0; i < flags.size(); i++){
if(flags.get(i)){
sbStr.append(files.get(i) + "' '");
}
}
if(sbStr.length() > 3){
sbStr.setLength(sbStr.length() - 3);
}
retStr = sbStr.toString();
}else{
//return current path
Intent intent = new Intent();
intent.putExtra(STRING_RETURN, currentDir.getAbsolutePath());
setResult(RESULT_OK, intent);
finish();
retStr = currentDir.getAbsolutePath();
}
intent.putExtra(STRING_RETURN, retStr);
setResult(RESULT_OK, intent);
finish();
break;
case id.buttonFcCancel:
finish();
Expand Down

0 comments on commit a1efe64

Please sign in to comment.