Skip to content

Commit

Permalink
Scan with LiveEdge
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesa2 committed Jun 24, 2020
1 parent e06ceea commit 86a4e21
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 20 deletions.
5 changes: 3 additions & 2 deletions owncloudApp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ dependencies {
implementation "androidx.sqlite:sqlite:$sqliteVersion"
implementation "androidx.biometric:biometric:$biometricVersion"

implementation 'com.github.hannesa2:CVScanner:0.9'
implementation 'com.github.hannesa2:CVScanner:1.0'
implementation 'com.github.hannesa2:LiveEdgeDetection:1.3.1'

// Tests
// Tests
testImplementation project(':owncloudTestUtil')
testImplementation "junit:junit:$junitVersion"
testImplementation "androidx.arch.core:core-testing:$archLifecycleVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ import com.owncloud.android.utils.PermissionUtil
import com.owncloud.android.utils.PreferenceUtils
import info.hannes.cvscanner.CVScanner
import info.hannes.github.AppUpdateHelper
import info.hannes.liveedgedetection.ScanConstants
import kotlinx.android.synthetic.main.nav_coordinator_layout.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -228,7 +229,12 @@ class FileDisplayActivity : FileActivity(), FileFragment.ContainerActivity, OnEn
AppRater.appLaunched(this, packageName)
}

AppUpdateHelper.checkForNewVersion(this, BuildConfig.GIT_USER, BuildConfig.GIT_REPOSITORY, BuildConfig.VERSION_NAME)
AppUpdateHelper.checkForNewVersion(
this,
BuildConfig.GIT_USER,
BuildConfig.GIT_REPOSITORY,
BuildConfig.VERSION_NAME
)
}

override fun onPostCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -648,19 +654,48 @@ class FileDisplayActivity : FileActivity(), FileFragment.ContainerActivity, OnEn

// requestUploadOfFilesFromFileSystem(data,resultCode);
} else if (requestCode == REQUEST_CODE__UPLOAD_SCANNED_DOCUMENT) {
if(resultCode == RESULT_OK) {
val scannedDocumentPath = data?.getStringExtra (CVScanner.RESULT_IMAGE_PATH);
if (resultCode == RESULT_OK) {
val scannedDocumentPath = data?.getStringExtra(CVScanner.RESULT_IMAGE_PATH)

filesUploadHelper!!.onActivityResult(scannedDocumentPath, object : FilesUploadHelper.OnCheckAvailableSpaceListener {
filesUploadHelper!!.onActivityResult(
scannedDocumentPath,
object : FilesUploadHelper.OnCheckAvailableSpaceListener {

override fun onCheckAvailableSpaceStart() = Unit
override fun onCheckAvailableSpaceStart() = Unit

override fun onCheckAvailableSpaceFinished(hasEnoughSpace: Boolean, capturedFilePaths: Array<String>) {
if (hasEnoughSpace) {
requestUploadOfFilesFromFileSystem(capturedFilePaths, FileUploader.LOCAL_BEHAVIOUR_MOVE)
override fun onCheckAvailableSpaceFinished(
hasEnoughSpace: Boolean,
capturedFilePaths: Array<String>
) {
if (hasEnoughSpace) {
requestUploadOfFilesFromFileSystem(capturedFilePaths, FileUploader.LOCAL_BEHAVIOUR_MOVE)
}
}
}
})
})
}
} else if (requestCode == REQUEST_CODE__UPLOAD_LIVEDGE_DOCUMENT) {
if (resultCode == RESULT_OK) {
data?.extras?.let { bundle ->
val scannedDocumentPath = bundle.getString(ScanConstants.SCANNED_RESULT)

filesUploadHelper!!.onActivityResult(scannedDocumentPath,
object : FilesUploadHelper.OnCheckAvailableSpaceListener {

override fun onCheckAvailableSpaceStart() = Unit

override fun onCheckAvailableSpaceFinished(
hasEnoughSpace: Boolean,
capturedFilePaths: Array<String>
) {
if (hasEnoughSpace) {
requestUploadOfFilesFromFileSystem(
capturedFilePaths,
FileUploader.LOCAL_BEHAVIOUR_MOVE
)
}
}
})
}
}
} else if (requestCode == REQUEST_CODE__MOVE_FILES && resultCode == Activity.RESULT_OK) {
handler.postDelayed(
Expand Down Expand Up @@ -1836,7 +1871,8 @@ class FileDisplayActivity : FileActivity(), FileFragment.ContainerActivity, OnEn
const val REQUEST_CODE__MOVE_FILES = REQUEST_CODE__LAST_SHARED + 2
const val REQUEST_CODE__COPY_FILES = REQUEST_CODE__LAST_SHARED + 3
const val REQUEST_CODE__UPLOAD_FROM_CAMERA = REQUEST_CODE__LAST_SHARED + 4
const val REQUEST_CODE__UPLOAD_SCANNED_DOCUMENT = REQUEST_CODE__LAST_SHARED + 5;
const val REQUEST_CODE__UPLOAD_SCANNED_DOCUMENT = REQUEST_CODE__LAST_SHARED + 5
const val REQUEST_CODE__UPLOAD_LIVEDGE_DOCUMENT = REQUEST_CODE__LAST_SHARED + 6
const val RESULT_OK_AND_MOVE = Activity.RESULT_FIRST_USER
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class ExtendedListFragment extends Fragment
private FloatingActionButton mFabUpload;
private FloatingActionButton mFabMkdir;
private FloatingActionButton mFabScan;
private FloatingActionButton mFabEdge;

// Save the state of the scroll in browsing
private ArrayList<Integer> mIndexes;
Expand Down Expand Up @@ -117,6 +118,10 @@ public FloatingActionButton getFabScan() {
return mFabScan;
}

public FloatingActionButton getFabEdge() {
return mFabEdge;
}

public FloatingActionsMenu getFabMain() {
return mFabMain;
}
Expand Down Expand Up @@ -188,6 +193,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
mFabUpload = v.findViewById(R.id.fab_upload);
mFabMkdir = v.findViewById(R.id.fab_mkdir);
mFabScan = v.findViewById(R.id.fab_scan);
mFabEdge = v.findViewById(R.id.fab_edge);

mCurrentListView = mListView; // list by default
if (savedInstanceState != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.PowerManager;
import android.preference.PreferenceManager;
Expand Down Expand Up @@ -80,6 +81,8 @@
import com.owncloud.android.ui.preview.PreviewVideoFragment;
import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.PreferenceUtils;
import info.hannes.liveedgedetection.ScanConstants;
import info.hannes.liveedgedetection.activity.ScanActivity;
import timber.log.Timber;
import info.hannes.cvscanner.CVScanner;

Expand Down Expand Up @@ -310,6 +313,7 @@ private void setFabLabels() {
getFabUpload().setTitle(getResources().getString(R.string.actionbar_upload));
getFabMkdir().setTitle(getResources().getString(R.string.actionbar_mkdir));
getFabScan().setTitle(getResources().getString(R.string.scan_document));
getFabEdge().setTitle(getResources().getString(R.string.scan_edge));
}

/**
Expand All @@ -334,6 +338,8 @@ public void onClick(View v) {
final LinearLayout uploadFilesLinearLayout = uploadBottomSheet.findViewById(R.id.files_linear_layout);
final LinearLayout scan_document_upload_linear_layout =
uploadBottomSheet.findViewById(R.id.scan_document_upload_linear_layout);
final LinearLayout scan_edge_upload_linear_layout =
uploadBottomSheet.findViewById(R.id.scan_edge_upload_linear_layout);
LinearLayout uploadFromCameraLinearLayout =
uploadBottomSheet.findViewById(R.id.upload_from_camera_linear_layout);
TextView uploadToTextView = uploadBottomSheet.findViewById(R.id.upload_to_text_view);
Expand All @@ -359,6 +365,14 @@ public void onClick(View v) {
dialog.hide();
return false;
});
scan_edge_upload_linear_layout.setOnTouchListener((v1, event) -> {
Intent intent = new Intent(getActivity(), ScanActivity.class);
intent.putExtra(ScanConstants.IMAGE_PATH, getActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES).toString());
getActivity().startActivityForResult(intent, FileDisplayActivity.REQUEST_CODE__UPLOAD_LIVEDGE_DOCUMENT);

dialog.hide();
return false;
});
uploadToTextView.setText(String.format(getResources().getString(R.string.upload_to),
getResources().getString(R.string.app_name)));
final BottomSheetBehavior uploadBottomSheetBehavior =
Expand All @@ -383,6 +397,15 @@ public void onClick(View v) {
FileDisplayActivity.REQUEST_CODE__UPLOAD_SCANNED_DOCUMENT);
}
});

getFabEdge().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), ScanActivity.class);
intent.putExtra(ScanConstants.IMAGE_PATH, getActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES).toString());
getActivity().startActivityForResult(intent, FileDisplayActivity.REQUEST_CODE__UPLOAD_LIVEDGE_DOCUMENT);
}
});
}

/**
Expand All @@ -409,6 +432,14 @@ public boolean onLongClick(View v) {
return true;
}
});

getFabEdge().setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
showSnackMessage(R.string.scan_edge);
return true;
}
});
}

/**
Expand All @@ -434,9 +465,11 @@ private void removeFabLabels() {
getFabUpload().setTitle(null);
getFabMkdir().setTitle(null);
getFabScan().setTitle(null);
getFabEdge().setTitle(null);
((TextView) getFabUpload().getTag(com.getbase.floatingactionbutton.R.id.fab_label)).setVisibility(View.GONE);
((TextView) getFabMkdir().getTag(com.getbase.floatingactionbutton.R.id.fab_label)).setVisibility(View.GONE);
((TextView) getFabScan().getTag(com.getbase.floatingactionbutton.R.id.fab_label)).setVisibility(View.GONE);
((TextView) getFabEdge().getTag(com.getbase.floatingactionbutton.R.id.fab_label)).setVisibility(View.GONE);
}

@Override
Expand Down
10 changes: 10 additions & 0 deletions owncloudApp/src/main/res/layout/list_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@
fab:fab_size="mini"
fab:fab_title="" />

<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_edge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@color/primary_button_background_color"
fab:fab_colorPressed="@color/owncloud_blue"
fab:fab_icon="@drawable/ic_bottom_sheets_scanner_white"
fab:fab_size="mini"
fab:fab_title="" />

<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_mkdir"
android:layout_width="wrap_content"
Expand Down
34 changes: 27 additions & 7 deletions owncloudApp/src/main/res/layout/upload_bottom_sheet_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
android:orientation="vertical">

<TextView
android:id="@+id/upload_to_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginStart="10dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="20dp"
android:text="@string/upload_to"
android:textColor="@color/grey"
android:id="@+id/upload_to_text_view"
android:textSize="15sp" />

<LinearLayout
Expand Down Expand Up @@ -62,23 +62,43 @@
</LinearLayout>

<LinearLayout
android:id="@+id/scan_document_upload_linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/scan_document_upload_linear_layout"
android:orientation="horizontal"
android:layout_marginBottom="20dp">
android:layout_marginBottom="20dp"
android:orientation="horizontal">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:src="@drawable/ic_bottom_sheets_scanner" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:text="@string/scan_document" />
</LinearLayout>

<LinearLayout
android:id="@+id/scan_edge_upload_linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:orientation="horizontal">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:src="@drawable/ic_bottom_sheets_scanner"/>
android:src="@drawable/ic_bottom_sheets_scanner" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:text="@string/scan_document"/>
android:text="@string/scan_edge" />

</LinearLayout>

Expand Down
1 change: 1 addition & 0 deletions owncloudApp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@
<string name="no_borwser_installed_alert">No browser installed. Please install a Browser in order to allow a secure login.</string>
<string name="common_not_found">it was not found</string>
<string name="scan_document">Scan document</string>
<string name="scan_edge">Scan edge document</string>

<string name="supports_oauth2_error">It was not possible to know if OAuth2 is supported</string>
<string name="get_base_url_error">It was not possible to know the server base url</string>
Expand Down

0 comments on commit 86a4e21

Please sign in to comment.