Skip to content

Commit

Permalink
Updating PPLE Android samples - v.1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
scandit-bot committed Sep 23, 2024
1 parent 85859d7 commit 8ba0637
Show file tree
Hide file tree
Showing 28 changed files with 298 additions and 158 deletions.
4 changes: 4 additions & 0 deletions JavaSettingsSample/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Java Settings Sample

Advanced sample that demonstrates the usage of all core features and every configuration options of the PPLE SDK.
The sample is written in java.
20 changes: 10 additions & 10 deletions JavaSettingsSample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ android {
}

dependencies {
implementation("com.scandit.shelf:pple-sdk:1.4.2")
implementation("com.scandit.shelf:pple-sdk:1.5.0")

implementation("androidx.appcompat:appcompat:1.6.1")
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.appcompat:appcompat:1.7.0")
implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.6.2")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
implementation("androidx.room:room-ktx:2.6.0")
implementation("androidx.room:room-runtime:2.6.0")
implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.7.0")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
implementation("androidx.room:room-ktx:2.6.1")
implementation("androidx.room:room-runtime:2.6.1")
implementation("androidx.security:security-crypto:1.1.0-alpha06")
implementation("androidx.startup:startup-runtime:1.1.1")
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01")
implementation("androidx.work:work-runtime-ktx:2.8.1")
implementation("com.google.android.material:material:1.10.0")
implementation("androidx.work:work-runtime-ktx:2.9.0")
implementation("com.google.android.material:material:1.12.0")
implementation("com.google.code.gson:gson:2.10.1")
implementation("com.squareup.okhttp3:logging-interceptor:4.12.0")
implementation("com.squareup.okhttp3:okhttp:4.12.0")
Expand Down
11 changes: 7 additions & 4 deletions JavaSettingsSample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="false"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="false"
android:icon="@mipmap/ic_pple_sample_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_pple_sample_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.SampleApp">
android:theme="@style/Theme.SampleApp"
tools:ignore="UnusedAttribute">
<activity
android:name=".MainActivity"
android:configChanges="orientation"
Expand All @@ -17,7 +22,5 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
Expand All @@ -26,9 +28,11 @@
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.MenuProvider;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.Lifecycle;

import com.google.android.material.snackbar.Snackbar;
import com.scandit.shelf.javasettingssample.R;
Expand All @@ -37,7 +41,7 @@
* Base Fragment that handles all basic setup operations such as setting up the toolbar, setting
* up navigation from/to the Fragment, inflating options menu and showing a Snackbar message.
*/
public class NavigationFragment extends Fragment {
public class NavigationFragment extends Fragment implements MenuProvider {

protected View root;

Expand All @@ -54,7 +58,7 @@ protected void setUpToolbar(Toolbar toolbar, String toolbarTitle, Boolean showBa
ActionBar actionBar = activity.getSupportActionBar();
if (actionBar != null) {
actionBar.show();
setHasOptionsMenu(true);
activity.addMenuProvider(this, getViewLifecycleOwner(), Lifecycle.State.RESUMED);
actionBar.setDisplayHomeAsUpEnabled(showBackButton);
actionBar.setHomeAsUpIndicator(R.drawable.ic_toolbar_back);
actionBar.setTitle(toolbarTitle);
Expand All @@ -63,11 +67,16 @@ protected void setUpToolbar(Toolbar toolbar, String toolbarTitle, Boolean showBa
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
requireActivity().onBackPressed();
public void onCreateMenu(@NonNull Menu menu, @NonNull MenuInflater menuInflater) {
// empty menu
}

@Override
public boolean onMenuItemSelected(@NonNull MenuItem menuItem) {
if (menuItem.getItemId() == android.R.id.home) {
requireActivity().getOnBackPressedDispatcher().onBackPressed();
}
return super.onOptionsItemSelected(item);
return true;
}

protected void clearBackStack() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public static SettingsOverviewFragment newInstance() {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(false);
viewModel = new ViewModelProvider(this).get(SettingsOverviewViewModel.class);
}

Expand Down Expand Up @@ -82,15 +81,9 @@ public void onEntryClick(SettingsOverviewEntry entry) {

private void moveToDeeperSettings(SettingsOverviewEntry entry) {
switch (entry) {
case FEEDBACK:
moveToFragment(FeedbackFragment.newInstance(), true, null);
break;
case VIEW:
moveToFragment(ViewSettingsOverviewFragment.newInstance(), true, null);
break;
case FLOW:
moveToFragment(FlowFragment.newInstance(), true, null);
break;
case FEEDBACK -> moveToFragment(FeedbackFragment.newInstance(), true, null);
case VIEW -> moveToFragment(ViewSettingsOverviewFragment.newInstance(), true, null);
case FLOW -> moveToFragment(FlowFragment.newInstance(), true, null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public static ViewSettingsOverviewFragment newInstance() {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(false);
viewModel = new ViewModelProvider(this).get(ViewSettingsOverviewViewModel.class);
}

Expand Down Expand Up @@ -82,15 +81,9 @@ public void onEntryClick(ViewSettingsOverviewEntry entry) {

private void moveToDeeperSettings(ViewSettingsOverviewEntry entry) {
switch (entry) {
case OVERLAY:
moveToFragment(OverlayFragment.newInstance(), true, null);
break;
case VIEWFINDER:
moveToFragment(ViewfinderFragment.newInstance(), true, null);
break;
case SCAN_AREA:
moveToFragment(ScanAreaFragment.newInstance(), true, null);
break;
case OVERLAY -> moveToFragment(OverlayFragment.newInstance(), true, null);
case VIEWFINDER -> moveToFragment(ViewfinderFragment.newInstance(), true, null);
case SCAN_AREA -> moveToFragment(ScanAreaFragment.newInstance(), true, null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -465,38 +465,38 @@ private void setupForRectangularViewfinder(ViewfinderTypeRectangular viewfinder)
SizeSpecification spec = viewfinder.getSizeSpecification();

switch (spec) {
case WIDTH_AND_HEIGHT:
case WIDTH_AND_HEIGHT -> {
containerHeight.setVisibility(View.VISIBLE);
containerWidth.setVisibility(View.VISIBLE);
containerShorterDimension.setVisibility(View.GONE);
containerHeightAspect.setVisibility(View.GONE);
containerWidthAspect.setVisibility(View.GONE);
containerLongerDimensionAspect.setVisibility(View.GONE);
break;
case HEIGHT_AND_WIDTH_ASPECT:
}
case HEIGHT_AND_WIDTH_ASPECT -> {
containerHeight.setVisibility(View.VISIBLE);
containerWidth.setVisibility(View.GONE);
containerShorterDimension.setVisibility(View.GONE);
containerHeightAspect.setVisibility(View.GONE);
containerWidthAspect.setVisibility(View.VISIBLE);
containerLongerDimensionAspect.setVisibility(View.GONE);
break;
case WIDTH_AND_HEIGHT_ASPECT:
}
case WIDTH_AND_HEIGHT_ASPECT -> {
containerHeight.setVisibility(View.GONE);
containerWidth.setVisibility(View.VISIBLE);
containerShorterDimension.setVisibility(View.GONE);
containerHeightAspect.setVisibility(View.VISIBLE);
containerWidthAspect.setVisibility(View.GONE);
containerLongerDimensionAspect.setVisibility(View.GONE);
break;
case SHORTER_DIMENSION_AND_ASPECT:
}
case SHORTER_DIMENSION_AND_ASPECT -> {
containerHeight.setVisibility(View.GONE);
containerWidth.setVisibility(View.GONE);
containerShorterDimension.setVisibility(View.VISIBLE);
containerHeightAspect.setVisibility(View.GONE);
containerWidthAspect.setVisibility(View.GONE);
containerLongerDimensionAspect.setVisibility(View.VISIBLE);
break;
}
}

refreshRectangularViewfinderData(viewfinder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,29 @@ public void setLineStyle(RectangularViewfinderLineStyle style) {
this.lineStyle = style;
}

public float getDimming() { return dimming; }
public float getDimming() {
return dimming;
}

public void setDimming(float dimming) { this.dimming = dimming; }
public void setDimming(float dimming) {
this.dimming = dimming;
}

public boolean getAnimation() { return animation; }
public boolean getAnimation() {
return animation;
}

public void setAnimation(boolean animation) { this.animation = animation; }
public void setAnimation(boolean animation) {
this.animation = animation;
}

public boolean getLooping() { return looping; }
public boolean getLooping() {
return looping;
}

public void setLooping(boolean looping) { this.looping = looping; }
public void setLooping(boolean looping) {
this.looping = looping;
}

@Nullable
@Override
Expand All @@ -221,19 +233,11 @@ public Viewfinder buildViewfinder() {
viewfinder.setAnimation(finalAnimation);

switch (sizeSpecification) {
case WIDTH_AND_HEIGHT:
viewfinder.setSize(new SizeWithUnit(width, height));
break;
case WIDTH_AND_HEIGHT_ASPECT:
viewfinder.setWidthAndAspectRatio(width, heightAspect);
break;
case HEIGHT_AND_WIDTH_ASPECT:
viewfinder.setHeightAndAspectRatio(height, widthAspect);
break;
case SHORTER_DIMENSION_AND_ASPECT:
viewfinder.setShorterDimensionAndAspectRatio(
shorterDimension.getValue(), longerDimensionAspect);
break;
case WIDTH_AND_HEIGHT -> viewfinder.setSize(new SizeWithUnit(width, height));
case WIDTH_AND_HEIGHT_ASPECT -> viewfinder.setWidthAndAspectRatio(width, heightAspect);
case HEIGHT_AND_WIDTH_ASPECT -> viewfinder.setHeightAndAspectRatio(height, widthAspect);
case SHORTER_DIMENSION_AND_ASPECT ->
viewfinder.setShorterDimensionAndAspectRatio(shorterDimension.getValue(), longerDimensionAspect);
}
return viewfinder;
}
Expand All @@ -254,22 +258,22 @@ public void resetDefaults() {
SizeWithUnitAndAspect size = viewfinder.getSizeWithUnitAndAspect();
sizeSpecification = SizeSpecification.forSizingMode(size.getSizingMode());
switch (sizeSpecification) {
case WIDTH_AND_HEIGHT:
case WIDTH_AND_HEIGHT -> {
width = size.getWidthAndHeight().getWidth();
height = size.getWidthAndHeight().getHeight();
break;
case WIDTH_AND_HEIGHT_ASPECT:
}
case WIDTH_AND_HEIGHT_ASPECT -> {
width = size.getWidthAndAspectRatio().getSize();
heightAspect = size.getWidthAndAspectRatio().getAspect();
break;
case HEIGHT_AND_WIDTH_ASPECT:
}
case HEIGHT_AND_WIDTH_ASPECT -> {
height = size.getHeightAndAspectRatio().getSize();
widthAspect = size.getHeightAndAspectRatio().getAspect();
break;
case SHORTER_DIMENSION_AND_ASPECT:
}
case SHORTER_DIMENSION_AND_ASPECT -> {
shorterDimension = size.getShorterDimensionAndAspectRatio().getSize();
longerDimensionAspect = size.getShorterDimensionAndAspectRatio().getAspect();
break;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,11 @@ public enum SizeSpecification {
}

public static SizeSpecification forSizingMode(SizingMode mode) {
switch (mode) {
case WIDTH_AND_ASPECT_RATIO:
return WIDTH_AND_HEIGHT_ASPECT;
case HEIGHT_AND_ASPECT_RATIO:
return HEIGHT_AND_WIDTH_ASPECT;
case SHORTER_DIMENSION_AND_ASPECT_RATIO:
return SHORTER_DIMENSION_AND_ASPECT;
default:
return WIDTH_AND_HEIGHT;
}
return switch (mode) {
case WIDTH_AND_ASPECT_RATIO -> WIDTH_AND_HEIGHT_ASPECT;
case HEIGHT_AND_ASPECT_RATIO -> HEIGHT_AND_WIDTH_ASPECT;
case SHORTER_DIMENSION_AND_ASPECT_RATIO -> SHORTER_DIMENSION_AND_ASPECT;
default -> WIDTH_AND_HEIGHT;
};
}
}
17 changes: 17 additions & 0 deletions JavaSettingsSample/src/main/res/xml/data_extraction_rules.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<data-extraction-rules>
<cloud-backup>
<exclude domain="root" />
<exclude domain="file" />
<exclude domain="database" />
<exclude domain="sharedpref" />
<exclude domain="external" />
</cloud-backup>
<device-transfer>
<exclude domain="root" />
<exclude domain="file" />
<exclude domain="database" />
<exclude domain="sharedpref" />
<exclude domain="external" />
</device-transfer>
</data-extraction-rules>
13 changes: 13 additions & 0 deletions JavaSimpleSample/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Java Simple Sample

Written in Java, rudimentary sample that shows how to quickly and easily set up Price Checking with PPLE SDK.
It is a single Activity (and without Fragments) application, that demonstrates how to:
1. authenticate with ShelfView credentials,
2. fetch the stores, product catalog and the config,
3. add the `CaptureView` UI component,
4. begin price checking.

The app applies the most typical settings you would expect in the price checking flow, including:
* a rectangular viewfinder placed in the middle of the screen,
* a restriction of the active scanning area to part of the screen within that viewfinder,
* AR overlays floating on top of the barcode belonging to the price label that has been detected within the active scan area.
Loading

0 comments on commit 8ba0637

Please sign in to comment.