Skip to content

Commit 4b0bd2d

Browse files
committed
add big preview, open photo with ImageViewer
1 parent df147aa commit 4b0bd2d

15 files changed

+311
-83
lines changed

app/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ dependencies {
2727
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
2828
implementation 'com.android.support:support-v4:28.0.0'
2929
implementation 'com.android.support:design:28.0.0'
30+
implementation 'net.zetetic:android-database-sqlcipher:4.4.2@aar'
31+
implementation "androidx.sqlite:sqlite:2.0.1"
3032
}

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
android:theme="@style/AppTheme">
1212
<activity android:name=".LoginActivity"></activity>
1313
<activity android:name=".VaultActivity" android:exported="false"/>
14+
<activity android:name=".ImageViewerActivity" android:exported="false"/>
1415
<activity android:name=".EntryActivity">
1516
<intent-filter>
1617
<action android:name="android.intent.action.MAIN" />

app/src/main/java/com/katcom/androidFileVault/FileVault.java

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -74,30 +74,7 @@ public Bitmap getPreview(ProtectedFile file,int sizeX,int sizeY){
7474
}
7575

7676
private Bitmap getPicturePreview(ProtectedFile file,int sizeX,int sizeY) {
77-
BitmapFactory.Options options = new BitmapFactory.Options();
78-
options.inJustDecodeBounds = true;
79-
BitmapFactory.decodeFile(file.getFilepath(),options);
80-
81-
float srcWidth = options.outWidth;
82-
float srcHeight = options.outHeight;
83-
84-
float targetWidth = Utils.dip2px(mContext,sizeX);
85-
float targetHeight = Utils.dip2px(mContext,sizeY);
86-
87-
// Scale the picture
88-
int inSampleSize = 1;
89-
if(srcHeight > targetHeight || srcHeight > targetHeight){
90-
if(srcWidth > targetWidth){
91-
inSampleSize = Math.round(srcWidth/targetWidth);
92-
}else{
93-
inSampleSize = Math.round(srcHeight/targetHeight);
94-
}
95-
}
96-
97-
options = new BitmapFactory.Options();
98-
options.inSampleSize = inSampleSize;
99-
100-
return BitmapFactory.decodeFile(file.getFilepath(),options);
77+
return Utils.getScaledBitmap(mContext,file.getFilepath(),sizeX,sizeY);
10178
}
10279

10380
public void importFile(String filepath){
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.katcom.androidFileVault;
2+
3+
import android.content.Context;
4+
import android.content.Intent;
5+
import android.support.v4.app.Fragment;
6+
7+
public class ImageViewerActivity extends SingleFragmentActivity {
8+
public static final String EXTRA_FILE_NAME= "com.katcom.adnroidFileVault.imageviewerIntent.filename";
9+
public static final String EXTRA_FILE_PATH = "com.katcom.adnroidFileVault.imageviewerIntent.filepath";
10+
11+
@Override
12+
protected Fragment createFragment() {
13+
String filename = (String)getIntent().getSerializableExtra(EXTRA_FILE_NAME);
14+
String filepath = (String)getIntent().getSerializableExtra(EXTRA_FILE_PATH);
15+
16+
return ImageViewerFragment.newInstance(filename,filepath);
17+
}
18+
19+
public static Intent newIntent(Context packageContext, String filename,String filepath){
20+
Intent intent = new Intent(packageContext, ImageViewerActivity.class);
21+
intent.putExtra(EXTRA_FILE_NAME,filename);
22+
intent.putExtra(EXTRA_FILE_PATH,filepath);
23+
return intent;
24+
}
25+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.katcom.androidFileVault;
2+
3+
import android.os.Bundle;
4+
import android.support.v4.app.Fragment;
5+
import android.support.v7.app.AlertDialog;
6+
import android.view.LayoutInflater;
7+
import android.view.View;
8+
import android.view.ViewGroup;
9+
import android.widget.ImageView;
10+
11+
public class ImageViewerFragment extends Fragment {
12+
private static final String ARG_FILE_PATH = "filepath";
13+
private static final String ARG_FILE_NAME = "filename";
14+
15+
private ImageView mImageView;
16+
@Override
17+
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
18+
View view = inflater.inflate(R.layout.fragment_image_viewer,container,false);
19+
String imgPath = getImagePath();
20+
String imgName = getImageName();
21+
mImageView = view.findViewById(R.id.fragment_image_viwer_image_view); // Bind the controller to the image view in the layout
22+
mImageView.setImageBitmap(Utils.getScaledBitmap(getContext(),imgPath,700,700));
23+
// Use the Builder class for convenient dialog construction
24+
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
25+
builder.setView(view);
26+
27+
// Create the AlertDialog object and return it
28+
return view;
29+
}
30+
31+
private String getImagePath() {
32+
return (String) getArguments().getSerializable(ARG_FILE_PATH);
33+
}
34+
35+
private String getImageName(){
36+
return (String) getArguments().getSerializable(ARG_FILE_NAME);
37+
}
38+
39+
40+
public static ImageViewerFragment newInstance(String filename,String filepath){
41+
Bundle args = new Bundle();
42+
args.putSerializable(ARG_FILE_PATH,filepath);
43+
args.putSerializable(ARG_FILE_NAME,filename);
44+
45+
ImageViewerFragment fragment = new ImageViewerFragment();
46+
fragment.setArguments(args);
47+
return fragment;
48+
}
49+
50+
51+
}

app/src/main/java/com/katcom/androidFileVault/PreviewMode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class PreviewMode {
1313
final public static String FILE_DETAIL = "File Detail";
1414
final public static String PREVIEW_SMALL = "Preview Small";
1515
final public static String PREVIEW_MEDIUM = "Preview Medium";
16-
//final public static String PREVIEW_BIG = "Preview Big";
16+
final public static String PREVIEW_BIG = "Preview Big";
1717
private static List<String> modes;
1818

1919
private PreviewMode(){}
@@ -23,6 +23,7 @@ private PreviewMode(){}
2323
modes.add(FILE_DETAIL);
2424
modes.add(PREVIEW_SMALL);
2525
modes.add(PREVIEW_MEDIUM);
26+
modes.add(PREVIEW_BIG);
2627
}
2728

2829
/**

app/src/main/java/com/katcom/androidFileVault/ProtectedFile.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ public ProtectedFile(String filename,String filepath,UUID id){
1414
this.id = id;
1515
}
1616

17-
public boolean isPicture(){
18-
//TODO
19-
return false;
20-
}
21-
2217
////////////////////////// Getter and Setter/////////////////////////////////////
2318
public UUID getId() {
2419
return id;

app/src/main/java/com/katcom/androidFileVault/Utils.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.content.Context;
44
import android.content.res.AssetManager;
55
import android.graphics.Bitmap;
6+
import android.graphics.BitmapFactory;
67
import android.util.Log;
78

89
import java.io.BufferedInputStream;
@@ -83,6 +84,42 @@ public static void copyFilesFromAsset(Context context,String source,String targe
8384
}
8485
}
8586

87+
/**
88+
* Load scaled picture from file
89+
* @param context
90+
* @param filepath the location of file
91+
* @param sizeX the desired width, measured in dp
92+
* @param sizeY the desired height, measured in dp
93+
* @return
94+
*/
95+
public static Bitmap getScaledBitmap(Context context,String filepath,int sizeX,int sizeY){
96+
BitmapFactory.Options options = new BitmapFactory.Options();
97+
options.inJustDecodeBounds = true;
98+
BitmapFactory.decodeFile(filepath,options);
99+
100+
float srcWidth = options.outWidth;
101+
float srcHeight = options.outHeight;
102+
103+
float targetWidth = Utils.dip2px(context,sizeX);
104+
float targetHeight = Utils.dip2px(context,sizeY);
105+
106+
// Scale the picture
107+
int inSampleSize = 1;
108+
if(srcHeight > targetHeight || srcHeight > targetHeight){
109+
if(srcWidth > targetWidth){
110+
inSampleSize = Math.round(srcWidth/targetWidth);
111+
}else{
112+
inSampleSize = Math.round(srcHeight/targetHeight);
113+
}
114+
}
115+
116+
options = new BitmapFactory.Options();
117+
options.inSampleSize = inSampleSize;
118+
119+
return BitmapFactory.decodeFile(filepath,options);
120+
}
121+
122+
86123
/**
87124
* Calculate px (pixel) from dp
88125
* @param context

0 commit comments

Comments
 (0)