Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration to Material3 #185

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions sample/src/main/java/io/runtime/mcumgr/sample/ScannerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.SimpleItemAnimator;

import com.google.android.material.color.MaterialColors;
import com.google.android.material.shape.MaterialShapeDrawable;

import javax.inject.Inject;

import io.runtime.mcumgr.sample.adapter.DevicesAdapter;
Expand Down Expand Up @@ -114,8 +117,7 @@ protected void onCreate(@Nullable final Bundle savedInstanceState) {
startActivity(launchIntro);
}

final Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
setSupportActionBar(binding.toolbar);
getSupportActionBar().setTitle(R.string.app_name);

// Create view model containing utility methods for scanning
Expand All @@ -124,7 +126,7 @@ protected void onCreate(@Nullable final Bundle savedInstanceState) {
scannerViewModel.getScannerState().observe(this, this::startScan);

// Configure the recycler view
final RecyclerView recyclerView = findViewById(R.id.recycler_view_ble_devices);
final RecyclerView recyclerView = binding.recyclerViewBleDevices;
recyclerView.setLayoutManager(new LinearLayoutManager(this));
final DividerItemDecoration dividerItemDecoration =
new DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.VERTICAL);
Expand All @@ -137,11 +139,13 @@ protected void onCreate(@Nullable final Bundle savedInstanceState) {

// Set up permission request launcher
final ActivityResultLauncher<String> requestPermission =
registerForActivityResult(new ActivityResultContracts.RequestPermission(),
registerForActivityResult(
new ActivityResultContracts.RequestPermission(),
result -> scannerViewModel.refresh()
);
);
final ActivityResultLauncher<String[]> requestPermissions =
registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(),
registerForActivityResult(
new ActivityResultContracts.RequestMultiplePermissions(),
result -> scannerViewModel.refresh()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import io.runtime.mcumgr.dfu.mcuboot.FirmwareUpgradeManager;
import io.runtime.mcumgr.sample.R;
import io.runtime.mcumgr.sample.fragment.mcumgr.ImageUpgradeFragment;
Expand All @@ -36,7 +38,7 @@ public Dialog onCreateDialog(@Nullable final Bundle savedInstanceState) {
selectedItem = 0;
}

return new AlertDialog.Builder(requireContext())
return new MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.image_upgrade_mode)
.setSingleChoiceItems(R.array.image_upgrade_mode_options, selectedItem,
(dialog, which) -> selectedItem = which)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import io.runtime.mcumgr.sample.R;
import io.runtime.mcumgr.sample.fragment.mcumgr.FilesUploadFragment;

Expand All @@ -43,7 +46,7 @@ public Dialog onCreateDialog(@Nullable final Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.dialog_generate_file, null);
final EditText fileSize = view.findViewById(R.id.file_size);

final AlertDialog dialog = new AlertDialog.Builder(requireContext())
final AlertDialog dialog = new MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.files_upload_generate_title)
.setView(view)
// Setting the positive button listener here would cause the dialog to dismiss.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatDialogFragment;
import androidx.fragment.app.DialogFragment;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import io.runtime.mcumgr.sample.R;

public class HelpDialogFragment extends AppCompatDialogFragment {
Expand Down Expand Up @@ -44,7 +46,7 @@ public Dialog onCreateDialog(@Nullable final Bundle savedInstanceState) {
final int titleResId = getArguments().getInt(ARG_TITLE_RES_ID);
final int messageResId = getArguments().getInt(ARG_MESSAGE_RES_ID);

return new AlertDialog.Builder(requireContext())
return new MaterialAlertDialogBuilder(requireContext())
.setIcon(R.drawable.ic_help)
.setTitle(titleResId)
.setMessage(messageResId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

import javax.inject.Inject;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import javax.inject.Inject;

import io.runtime.mcumgr.sample.R;
import io.runtime.mcumgr.sample.di.Injectable;
import io.runtime.mcumgr.sample.utils.FsUtils;
Expand Down Expand Up @@ -52,7 +55,7 @@ public Dialog onCreateDialog(@Nullable final Bundle savedInstanceState) {
partition.setText(fsUtils.getPartitionString());
partition.selectAll();

final AlertDialog dialog = new AlertDialog.Builder(requireContext())
final AlertDialog dialog = new MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.files_settings_title)
.setView(view)
// Setting the positive button listener here would cause the dialog to dismiss.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import io.runtime.mcumgr.sample.R;
import io.runtime.mcumgr.sample.databinding.DialogSelectImageBinding;

Expand Down Expand Up @@ -38,7 +40,7 @@ public Dialog onCreateDialog(@Nullable final Bundle savedInstanceState) {
binding.image.setText(items[0], false);
binding.image.setOnItemClickListener((parent, view, position, id) -> this.position = position);

return new AlertDialog.Builder(requireContext())
return new MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.image_select_image)
.setView(binding.getRoot())
// Setting the positive button listener here would cause the dialog to dismiss.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;

public class YesNoDialogFragment extends DialogFragment {
private static final String ARG_REQUEST_ID = "requestId";
private static final String ARG_TITLE_ID = "titleId";
Expand Down Expand Up @@ -37,7 +38,7 @@ public Dialog onCreateDialog(@Nullable final Bundle savedInstanceState) {
final Bundle args = requireArguments();
final int requestId = args.getInt(ARG_REQUEST_ID);

return new AlertDialog.Builder(requireContext())
return new MaterialAlertDialogBuilder(requireContext())
.setTitle(args.getInt(ARG_TITLE_ID))
.setMessage(args.getInt(ARG_QUESTION_ID))
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
Expand Down
2 changes: 0 additions & 2 deletions sample/src/main/res/drawable/ic_help.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="@color/colorOnSurface"
android:alpha="0.6"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/res/layout-land/activity_intro.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@

<com.google.android.material.button.MaterialButton
android:id="@+id/button_continue"
style="@style/Widget.MaterialComponents.Button"
style="@style/Widget.Material3.Button.UnelevatedButton"
android:layout_width="200dp"
android:layout_height="52dp"
android:layout_marginBottom="48dp"
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/res/layout/activity_intro.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@

<com.google.android.material.button.MaterialButton
android:id="@+id/button_continue"
style="@style/Widget.MaterialComponents.Button"
style="@style/Widget.Material3.Button.UnelevatedButton"
android:layout_width="200dp"
android:layout_height="52dp"
android:layout_marginBottom="48dp"
Expand Down
6 changes: 3 additions & 3 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
android:background="@color/appBarColor"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
Expand Down Expand Up @@ -50,9 +51,8 @@
android:name="io.runtime.mcumgr.sample.fragment.mcumgr.DeviceStatusFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="16dp"
tools:layout="@layout/fragment_card_device_status"/>

<androidx.fragment.app.FragmentContainerView
Expand Down
1 change: 1 addition & 0 deletions sample/src/main/res/layout/activity_scanner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
android:background="@color/appBarColor"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
Expand Down
5 changes: 3 additions & 2 deletions sample/src/main/res/layout/dialog_files_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:paddingHorizontal="16dp"
android:paddingTop="16dp"
android:orientation="vertical">

<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
style="?textInputOutlinedStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/files_settings_partition">
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/res/layout/dialog_generate_file.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
android:gravity="center_vertical">

<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
style="?textInputOutlinedStyle"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
Expand Down
5 changes: 3 additions & 2 deletions sample/src/main/res/layout/dialog_select_image.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:paddingHorizontal="16dp"
android:paddingTop="16dp"
android:orientation="vertical">

<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
style="?textInputOutlinedExposedDropdownMenuStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/image_select_image">
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/res/layout/fragment_card_device_status.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp">
android:layout_marginBottom="16dp">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
Expand Down
6 changes: 3 additions & 3 deletions sample/src/main/res/layout/fragment_card_echo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp">
android:layout_marginBottom="16dp">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
Expand All @@ -30,7 +30,7 @@

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/echo_layout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
style="?textInputOutlinedStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
Expand All @@ -51,7 +51,7 @@

<com.google.android.material.button.MaterialButton
android:id="@+id/action_send"
style="@style/Widget.MaterialComponents.Button"
style="@style/Widget.Material3.Button.UnelevatedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
Expand Down
17 changes: 8 additions & 9 deletions sample/src/main/res/layout/fragment_card_exec.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp">
android:layout_marginBottom="16dp">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
Expand Down Expand Up @@ -56,10 +56,10 @@

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/exec_layout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
style="?textInputOutlinedStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_weight="1"
Expand All @@ -76,21 +76,20 @@
tools:text="rm -R /"/>
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button"
<Button
style="@style/Widget.Material3.Button.IconButton"
android:id="@+id/action_history"
android:layout_width="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginEnd="8dp"
app:icon="@drawable/ic_history"
android:paddingLeft="12dp"
app:layout_constraintBottom_toBottomOf="@+id/exec_layout"
app:layout_constraintEnd_toStartOf="@+id/action_send"
app:layout_constraintTop_toTopOf="@+id/exec_layout" />

<com.google.android.material.button.MaterialButton
android:id="@+id/action_send"
style="@style/Widget.MaterialComponents.Button"
style="@style/Widget.Material3.Button.UnelevatedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
Expand Down
Loading