import also for scan

This commit is contained in:
ligi 2013-02-07 23:58:17 +01:00
parent 3fdbed6b45
commit 200a2fe739
3 changed files with 301 additions and 203 deletions

View file

@ -9,6 +9,7 @@ import com.actionbarsherlock.view.Menu;
import java.io.File;
import java.io.InputStream;
import java.util.concurrent.Callable;
public class TicketImportActivity extends SherlockActivity {
@ -33,7 +34,12 @@ public class TicketImportActivity extends SherlockActivity {
i.putExtra("path", path);
(new File(path)).mkdirs();
UnzipPasscodeDialog.show(result, path, ticketImportActivity, i);
UnzipPasscodeDialog.show(result, path, ticketImportActivity, new Callable<Void>() {
@Override
public Void call() throws Exception {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
});
}
super.onPostExecute(result);
}

View file

@ -1,16 +1,15 @@
package org.ligi.ticketviewer;
import java.io.File;
import java.io.FilenameFilter;
import org.json.JSONArray;
import org.json.JSONObject;
import org.ligi.ticketviewer.helper.FileHelper;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
@ -20,8 +19,16 @@ import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockListActivity;
import com.actionbarsherlock.view.Window;
import org.json.JSONArray;
import org.json.JSONObject;
import org.ligi.ticketviewer.helper.FileHelper;
import java.io.File;
import java.io.FilenameFilter;
import java.io.InputStream;
import java.util.concurrent.Callable;
public class TicketListActivity extends SherlockListActivity {
@ -30,18 +37,20 @@ public class TicketListActivity extends SherlockListActivity {
private String path;
private PassAdapter passadapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
path = TicketDefinitions.getPassesDir(this);
File passes_dir=new File(TicketDefinitions.getPassesDir(this));
if (!passes_dir.exists())
passes_dir.mkdirs();
passes =passes_dir.list(new DirFilter());
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
refresh_passes_list();
passadapter = new PassAdapter();
setListAdapter(passadapter);
inflater = getLayoutInflater();
super.onCreate(savedInstanceState);
getListView().setOnItemClickListener(new OnItemClickListener() {
@Override
@ -54,7 +63,7 @@ public class TicketListActivity extends SherlockListActivity {
});
TextView empty_view = new TextView(this);
empty_view.setText("No passes yet - go get some and come back");
empty_view.setText("No passes yet - searching for passes");
//getListView().setEmptyView(empty_view);
empty_view.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
@ -62,9 +71,86 @@ public class TicketListActivity extends SherlockListActivity {
((ViewGroup) getListView().getParent()).addView(empty_view);
getListView().setEmptyView(empty_view);
setSupportProgressBarIndeterminateVisibility(true);
new ScanForPassesTask().execute();
}
private void refresh_passes_list() {
path = TicketDefinitions.getPassesDir(this);
File passes_dir = new File(TicketDefinitions.getPassesDir(this));
if (!passes_dir.exists())
passes_dir.mkdirs();
passes = passes_dir.list(new DirFilter());
}
class ImportAndShowAsyncTask extends ImportAsyncTask {
public ImportAndShowAsyncTask(Activity ticketImportActivity, Uri intent_uri) {
super(ticketImportActivity, intent_uri);
}
@Override
protected void onPostExecute(InputStream result) {
if (result != null) {
String path = TicketDefinitions.getTmpDir(ticketImportActivity);
(new File(path)).mkdirs();
UnzipPasscodeDialog.show(result, path, ticketImportActivity, new Callable<Void>() {
@Override
public Void call() throws Exception {
Log.i("", "refreshing");
runOnUiThread(new Runnable() {
@Override
public void run() {
refresh_passes_list();
passadapter.notifyDataSetChanged();
}
});
return null; //To change body of implemented methods use File | Settings | File Templates.
}
});
}
super.onPostExecute(result);
}
}
class ScanForPassesTask extends AsyncTask<Void, Void, Void> {
private void search_in(String path) {
Log.i("", "search in" + path);
File dir = new File(path);
File[] files = dir.listFiles();
for (File file : files) {
if (file.isDirectory())
search_in(file.toString());
else if (file.getName().endsWith(".pkpass")) {
Log.i("TicketViewer", "found" + file.getAbsolutePath());
new ImportAndShowAsyncTask(TicketListActivity.this, Uri.parse("file://" + file.getAbsolutePath())).execute();
}
}
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid); //To change body of overridden methods use File | Settings | File Templates.
setSupportProgressBarIndeterminateVisibility(false);
}
@Override
protected Void doInBackground(Void... params) {
search_in("/sdcard");
return null;
}
}
@Override
protected void onResume() {
@ -75,7 +161,12 @@ public class TicketListActivity extends SherlockListActivity {
}
class SearchForFilesDialog extends Dialog {
public SearchForFilesDialog(Context context) {
super(context);
}
}
class DirFilter implements FilenameFilter {

View file

@ -1,19 +1,20 @@
package org.ligi.ticketviewer;
import android.app.Activity;
import android.app.ProgressDialog;
import android.util.Log;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.concurrent.Callable;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.util.Log;
public class UnzipPasscodeDialog {
public final static String TAG = "TicketViewer";
public static class Decompress {
private InputStream _zipFile;
private String _location;
@ -67,24 +68,18 @@ public class UnzipPasscodeDialog {
}
/**
*
* @param activity
* @param autoclose
* - if the alert should close when connection is established
*
* @param activity - if the alert should close when connection is established
*/
public static void show(final InputStream ins,final String path,Activity activity, Intent intent_after_finish) {
public static void show(final InputStream ins, final String path, Activity activity, Callable<Void> intent_after_finish) {
ProgressDialog dialog = ProgressDialog.show(activity, "", "Opening the Passbook. Please wait...", true);
class AlertDialogUpdater implements Runnable {
private ProgressDialog myProgress;
private Activity activity;
private Intent intent_after_finish;
private Callable intent_after_finish;
public AlertDialogUpdater(Activity activity, ProgressDialog progress, Intent intent_after_finish) {
this.activity = activity;
public AlertDialogUpdater(Activity activity, ProgressDialog progress, Callable intent_after_finish) {
this.intent_after_finish = intent_after_finish;
myProgress = progress;
}
@ -94,8 +89,14 @@ public class UnzipPasscodeDialog {
myProgress.dismiss();
activity.startActivity(intent_after_finish);
activity.finish();
try {
intent_after_finish.call();
} catch (Exception e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
// activity.startActivity(intent_after_finish);
// activity.finish();
}
}