Skip to content

Commit

Permalink
List of included changes:
Browse files Browse the repository at this point in the history
  - Do not show CameraX activities on api level < 21 for automl app

PiperOrigin-RevId: 410937658
Change-Id: I15c86170102cb7c35beb42a7c12fe396d601937e
  • Loading branch information
Google ML Kit authored and Yun Liu committed Nov 19, 2021
1 parent 39564c8 commit 58b41da
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
Expand Down Expand Up @@ -96,16 +95,6 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "onCreate");

if (VERSION.SDK_INT < VERSION_CODES.LOLLIPOP) {
Toast.makeText(
getApplicationContext(),
"CameraX is only supported on SDK version >=21. Current SDK version is "
+ VERSION.SDK_INT,
Toast.LENGTH_LONG)
.show();
return;
}

if (savedInstanceState != null) {
selectedModel = savedInstanceState.getString(STATE_SELECTED_MODEL, CUSTOM_AUTOML_LABELING);
lensFacing = savedInstanceState.getInt(STATE_LENS_FACING, CameraSelector.LENS_FACING_BACK);
Expand Down Expand Up @@ -152,13 +141,13 @@ protected void onCreate(Bundle savedInstanceState) {

ImageView settingsButton = findViewById(R.id.settings_button);
settingsButton.setOnClickListener(
v -> {
Intent intent = new Intent(getApplicationContext(), SettingsActivity.class);
intent.putExtra(
SettingsActivity.EXTRA_LAUNCH_SOURCE,
SettingsActivity.LaunchSource.CAMERAX_LIVE_PREVIEW);
startActivity(intent);
});
v -> {
Intent intent = new Intent(getApplicationContext(), SettingsActivity.class);
intent.putExtra(
SettingsActivity.EXTRA_LAUNCH_SOURCE,
SettingsActivity.LaunchSource.CAMERAX_LIVE_PREVIEW);
startActivity(intent);
});

if (!allPermissionsGranted()) {
getRuntimePermissions();
Expand Down Expand Up @@ -311,7 +300,7 @@ private void bindAnalysisUseCase() {
default:
throw new IllegalStateException("Invalid model name");
}
} catch (Exception e) {
} catch (RuntimeException e) {
Log.e(TAG, "Can not create image processor: " + selectedModel, e);
Toast.makeText(
getApplicationContext(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.os.StrictMode;
import androidx.appcompat.app.AppCompatActivity;
Expand Down Expand Up @@ -48,16 +50,24 @@ public final class ChooserActivity extends AppCompatActivity

@SuppressWarnings("NewApi") // CameraX is only available on API 21+
private static final Class<?>[] CLASSES =
new Class<?>[] {
LivePreviewActivity.class, StillImageActivity.class, CameraXLivePreviewActivity.class,
};
VERSION.SDK_INT < VERSION_CODES.LOLLIPOP
? new Class<?>[] {
LivePreviewActivity.class, StillImageActivity.class,
}
: new Class<?>[] {
LivePreviewActivity.class, StillImageActivity.class, CameraXLivePreviewActivity.class,
};

private static final int[] DESCRIPTION_IDS =
new int[] {
R.string.desc_camera_source_activity,
R.string.desc_still_image_activity,
R.string.desc_camerax_live_preview_activity,
};
VERSION.SDK_INT < VERSION_CODES.LOLLIPOP
? new int[] {
R.string.desc_camera_source_activity, R.string.desc_still_image_activity,
}
: new int[] {
R.string.desc_camera_source_activity,
R.string.desc_still_image_activity,
R.string.desc_camerax_live_preview_activity,
};

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down

0 comments on commit 58b41da

Please sign in to comment.