weird case for ligi

This commit is contained in:
Vincent Breitmoser 2015-06-04 15:05:04 +02:00
parent fa61438306
commit b01dd39bd7
4 changed files with 110 additions and 46 deletions

View File

@ -19,6 +19,7 @@ package org.sufficientlysecure.keychain.ui;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -31,6 +32,7 @@ import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
@ -70,9 +72,9 @@ import org.sufficientlysecure.keychain.ui.adapter.SpacesItemDecoration;
import org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment; import org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment;
import org.sufficientlysecure.keychain.ui.util.FormattingUtils; import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.StatusHolder;
import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.ui.util.Notify.Style; import org.sufficientlysecure.keychain.ui.util.Notify.Style;
import org.sufficientlysecure.keychain.ui.util.StatusHolder;
import org.sufficientlysecure.keychain.util.FileHelper; import org.sufficientlysecure.keychain.util.FileHelper;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
@ -162,11 +164,20 @@ public class DecryptFilesListFragment extends CryptoOperationFragment implements
public void onActivityResult(int requestCode, int resultCode, Intent data) { public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) { switch (requestCode) {
case REQUEST_CODE_OUTPUT: { case REQUEST_CODE_OUTPUT: {
Activity activity = getActivity();
if (activity == null) {
mCurrentInputUri = null;
return;
}
// This happens after output file was selected, so start our operation // This happens after output file was selected, so start our operation
if (resultCode == Activity.RESULT_OK && data != null) { if (resultCode == Activity.RESULT_OK && data != null) {
Uri saveUri = data.getData(); Uri saveUri = data.getData();
Uri outputUri = mOutputUris.get(mCurrentInputUri); Uri decryptedDataUri = mOutputUris.get(mCurrentInputUri);
// TODO save from outputUri to saveUri try {
FileHelper.copyUri(getActivity(), decryptedDataUri, saveUri);
} catch (IOException e) {
Notify.create(activity, "Error saving file!", Style.ERROR).show();
}
mCurrentInputUri = null; mCurrentInputUri = null;
} }
@ -236,8 +247,16 @@ public class DecryptFilesListFragment extends CryptoOperationFragment implements
} }
Uri outputUri = mOutputUris.get(uri); Uri outputUri = mOutputUris.get(uri);
Intent intent = new Intent(); Intent intent = new Intent(Intent.ACTION_SEND);
intent.setDataAndType(outputUri, metadata.getMimeType()); intent.setType(metadata.getMimeType());
intent.putExtra(Intent.EXTRA_STREAM, outputUri);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (Build.VERSION.SDK_INT < VERSION_CODES.LOLLIPOP) {
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
} else {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
}
// activity.startActivity(Intent.createChooser(intent, null));
activity.startActivity(intent); activity.startActivity(intent);
} }
}; };
@ -388,7 +407,7 @@ public class DecryptFilesListFragment extends CryptoOperationFragment implements
return false; return false;
} }
public static class DecryptFilesAdapter extends RecyclerView.Adapter<ViewHolder> { public static class DecryptFilesAdapter extends RecyclerView.Adapter<DecryptItemViewHolder> {
private Context mContext; private Context mContext;
private ArrayList<ViewModel> mDataset; private ArrayList<ViewModel> mDataset;
private OnMenuItemClickListener mMenuItemClickListener; private OnMenuItemClickListener mMenuItemClickListener;
@ -469,16 +488,16 @@ public class DecryptFilesListFragment extends CryptoOperationFragment implements
// Create new views (invoked by the layout manager) // Create new views (invoked by the layout manager)
@Override @Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { public DecryptItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//inflate your layout and pass it to view holder //inflate your layout and pass it to view holder
View v = LayoutInflater.from(parent.getContext()) View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.decrypt_list_entry, parent, false); .inflate(R.layout.decrypt_list_entry, parent, false);
return new ViewHolder(v); return new DecryptItemViewHolder(v);
} }
// Replace the contents of a view (invoked by the layout manager) // Replace the contents of a view (invoked by the layout manager)
@Override @Override
public void onBindViewHolder(ViewHolder holder, final int position) { public void onBindViewHolder(DecryptItemViewHolder holder, final int position) {
// - get element from your dataset at this position // - get element from your dataset at this position
// - replace the contents of the view with that element // - replace the contents of the view with that element
final ViewModel model = mDataset.get(position); final ViewModel model = mDataset.get(position);
@ -577,11 +596,21 @@ public class DecryptFilesListFragment extends CryptoOperationFragment implements
} }
private Drawable loadIcon(String mimeType) {
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setType(mimeType);
// Provide a reference to the views for each data item final List<ResolveInfo> matches = getActivity()
// Complex data items may need more than one view per item, and .getPackageManager().queryIntentActivities(intent, 0);
// you provide access to all the views for a data item in a view holder //noinspection LoopStatementThatDoesntLoop
public static class ViewHolder extends RecyclerView.ViewHolder implements StatusHolder { for (ResolveInfo match : matches) {
return match.loadIcon(getActivity().getPackageManager());
}
return null;
}
public static class DecryptItemViewHolder extends RecyclerView.ViewHolder implements StatusHolder {
public ViewAnimator vAnimator; public ViewAnimator vAnimator;
public ProgressBar vProgress; public ProgressBar vProgress;
@ -604,7 +633,7 @@ public class DecryptFilesListFragment extends CryptoOperationFragment implements
public View vContextMenu; public View vContextMenu;
public ViewHolder(View itemView) { public DecryptItemViewHolder(View itemView) {
super(itemView); super(itemView);
vAnimator = (ViewAnimator) itemView.findViewById(R.id.view_animator); vAnimator = (ViewAnimator) itemView.findViewById(R.id.view_animator);
@ -624,7 +653,7 @@ public class DecryptFilesListFragment extends CryptoOperationFragment implements
vSigStatusText = (TextView) itemView.findViewById(R.id.result_signature_text); vSigStatusText = (TextView) itemView.findViewById(R.id.result_signature_text);
vSignatureLayout = itemView.findViewById(R.id.result_signature_layout); vSignatureLayout = itemView.findViewById(R.id.result_signature_layout);
vSignatureName = (TextView) itemView.findViewById(R.id.result_signature_name); vSignatureName = (TextView) itemView.findViewById(R.id.result_signature_name);
vSignatureMail= (TextView) itemView.findViewById(R.id.result_signature_email); vSignatureMail = (TextView) itemView.findViewById(R.id.result_signature_email);
vSignatureAction = (TextView) itemView.findViewById(R.id.result_signature_action); vSignatureAction = (TextView) itemView.findViewById(R.id.result_signature_action);
vContextMenu = itemView.findViewById(R.id.context_menu); vContextMenu = itemView.findViewById(R.id.context_menu);
@ -676,19 +705,4 @@ public class DecryptFilesListFragment extends CryptoOperationFragment implements
return true; return true;
} }
} }
private Drawable loadIcon(String mimeType) {
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setType(mimeType);
final List<ResolveInfo> matches = getActivity()
.getPackageManager().queryIntentActivities(intent, 0);
//noinspection LoopStatementThatDoesntLoop
for (ResolveInfo match : matches) {
return match.loadIcon(getActivity().getPackageManager());
}
return null;
}
} }

View File

@ -423,22 +423,6 @@ public class KeyFormattingUtils {
setStatusImage(context, statusIcon, statusText, state, color, false); setStatusImage(context, statusIcon, statusText, state, color, false);
} }
public interface StatusHolder {
ImageView getEncryptionStatusIcon();
TextView getEncryptionStatusText();
ImageView getSignatureStatusIcon();
TextView getSignatureStatusText();
View getSignatureLayout();
TextView getSignatureUserName();
TextView getSignatureUserEmail();
TextView getSignatureAction();
boolean hasEncrypt();
}
@SuppressWarnings("deprecation") // context.getDrawable is api lvl 21, need to use deprecated @SuppressWarnings("deprecation") // context.getDrawable is api lvl 21, need to use deprecated
public static void setStatus(Context context, StatusHolder holder, DecryptVerifyResult result) { public static void setStatus(Context context, StatusHolder holder, DecryptVerifyResult result) {

View File

@ -0,0 +1,29 @@
package org.sufficientlysecure.keychain.ui.util;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
public interface StatusHolder {
ImageView getEncryptionStatusIcon();
TextView getEncryptionStatusText();
ImageView getSignatureStatusIcon();
TextView getSignatureStatusText();
View getSignatureLayout();
TextView getSignatureUserName();
TextView getSignatureUserEmail();
TextView getSignatureAction();
boolean hasEncrypt();
}

View File

@ -37,11 +37,15 @@ import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.widget.Toast; import android.widget.Toast;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround; import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround;
import org.sufficientlysecure.keychain.ui.dialog.FileDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.FileDialogFragment;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.DecimalFormat; import java.text.DecimalFormat;
public class FileHelper { public class FileHelper {
@ -237,4 +241,37 @@ public class FileHelper {
public static interface FileDialogCallback { public static interface FileDialogCallback {
public void onFileSelected(File file, boolean checked); public void onFileSelected(File file, boolean checked);
} }
public static void copyUri(Context context, Uri from, Uri to) throws IOException {
InputStream in = null;
OutputStream out = null;
try {
in = context.getContentResolver().openInputStream(from);
out = context.getContentResolver().openOutputStream(to);
copyStream(in, out);
} catch (IOException e) {
Log.e(Constants.TAG, "io exception while copying uri streams", e);
throw e;
} finally {
if (in != null) try {
in.close();
} catch (IOException e) {
// nvm
}
if (out != null) try {
out.close();
} catch (IOException e) {
// nvm
}
}
}
public static void copyStream(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
while((read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
}
} }