From 038e8bb174eb5c4b80281d0bb97133091067c261 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste <87148630+Jean-BaptisteC@users.noreply.github.com> Date: Fri, 29 Mar 2024 18:06:38 +0100 Subject: [PATCH] Material 3 Migration (#26) --- .../foucry/pilldroid/DrugDetailActivity.java | 4 +- .../foucry/pilldroid/DrugDetailFragment.java | 31 +++---- .../foucry/pilldroid/DrugListActivity.java | 39 ++++----- .../net/foucry/pilldroid/WelcomeActivity.java | 20 ++--- app/src/main/res/drawable/arrow_back.xml | 11 +++ app/src/main/res/layout/about.xml | 25 ++++-- .../res/layout/custom_barcode_scanner.xml | 2 +- app/src/main/res/layout/custom_btn.xml | 2 +- .../custom_dialog_layout_one_button.xml | 12 +-- .../custom_dialog_layout_two_button.xml | 14 ++-- .../main/res/layout/drug_detail_activity.xml | 3 +- .../main/res/layout/drug_list_activity.xml | 4 +- app/src/main/res/layout/drug_list_content.xml | 8 +- app/src/main/res/layout/info_cell.xml | 11 ++- app/src/main/res/layout/input_dialog.xml | 8 +- app/src/main/res/layout/value_input.xml | 83 ++++++++++--------- app/src/main/res/layout/welcome1.xml | 6 +- app/src/main/res/layout/welcome10.xml | 6 +- app/src/main/res/layout/welcome11.xml | 6 +- app/src/main/res/layout/welcome12.xml | 6 +- app/src/main/res/layout/welcome2.xml | 6 +- app/src/main/res/layout/welcome3.xml | 6 +- app/src/main/res/layout/welcome4.xml | 6 +- app/src/main/res/layout/welcome5.xml | 4 +- app/src/main/res/layout/welcome6.xml | 4 +- app/src/main/res/layout/welcome7.xml | 4 +- app/src/main/res/layout/welcome8.xml | 4 +- app/src/main/res/layout/welcome9.xml | 4 +- app/src/main/res/layout/welcome_activity.xml | 9 +- app/src/main/res/values/styles.xml | 7 +- 30 files changed, 196 insertions(+), 159 deletions(-) create mode 100644 app/src/main/res/drawable/arrow_back.xml diff --git a/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java index 7e3c5ab..3993f11 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java @@ -6,12 +6,12 @@ import android.util.Log; import android.view.MenuItem; import android.view.View; import android.widget.EditText; -import android.widget.ImageButton; import android.widget.TextView; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import com.google.android.material.appbar.MaterialToolbar; +import com.google.android.material.floatingactionbutton.FloatingActionButton; import net.foucry.pilldroid.dao.PrescriptionsDAO; import net.foucry.pilldroid.databases.PrescriptionDatabase; import net.foucry.pilldroid.models.Prescription; @@ -46,7 +46,7 @@ public class DrugDetailActivity extends AppCompatActivity { setSupportActionBar(toolbar); } - ImageButton fab = findViewById(R.id.fab); + FloatingActionButton fab = findViewById(R.id.fab); fab.setOnClickListener(v -> { Log.d(TAG, "Click on save icon"); diff --git a/app/src/main/java/net/foucry/pilldroid/DrugDetailFragment.java b/app/src/main/java/net/foucry/pilldroid/DrugDetailFragment.java index a155349..566d8ec 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugDetailFragment.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugDetailFragment.java @@ -5,10 +5,11 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.TextView; import androidx.fragment.app.Fragment; import com.google.android.material.appbar.MaterialToolbar; +import com.google.android.material.textfield.TextInputEditText; +import com.google.android.material.textview.MaterialTextView; import net.foucry.pilldroid.models.Prescription; /** @@ -72,34 +73,34 @@ public class DrugDetailFragment extends Fragment { if (prescription != null) { // Find each component of rootView nameView = detailView.findViewById(R.id.name_cell); - TextView nameLabel = nameView.findViewById(R.id.label); - TextView nameValue = nameView.findViewById(R.id.value); + MaterialTextView nameLabel = nameView.findViewById(R.id.label); + MaterialTextView nameValue = nameView.findViewById(R.id.value); nameLabel.setText(R.string.drug_name_label); nameValue.setText(prescription.getName()); presentationView = detailView.findViewById(R.id.presentation_cell); - TextView presentationLabel = presentationView.findViewById(R.id.label); - TextView presentationValue = presentationView.findViewById(R.id.value); + MaterialTextView presentationLabel = presentationView.findViewById(R.id.label); + MaterialTextView presentationValue = presentationView.findViewById(R.id.value); presentationLabel.setText(R.string.drug_presentation_label); presentationValue.setText(prescription.getPresentation()); adminModeView = detailView.findViewById(R.id.administration_cell); - TextView adminModeLabel = adminModeView.findViewById(R.id.label); - TextView adminModeValue = adminModeView.findViewById(R.id.value); + MaterialTextView adminModeLabel = adminModeView.findViewById(R.id.label); + MaterialTextView adminModeValue = adminModeView.findViewById(R.id.value); adminModeLabel.setText(R.string.drug_administrationMode_label); adminModeValue.setText(prescription.getAdministration_mode()); stockView = detailView.findViewById(R.id.stock_cell); - TextView stockLibelle = (stockView.findViewById(R.id.label)); - TextView stockValue = stockView.findViewById(R.id.value); + MaterialTextView stockLibelle = (stockView.findViewById(R.id.label)); + TextInputEditText stockValue = stockView.findViewById(R.id.value); stockLibelle.setText(R.string.drug_current_stock_label); stockValue.setText(Utils.fmt(prescription.getStock())); stockValue.setHint(R.string.drug_current_stock_label); stockValue.setSelectAllOnFocus(true); takeView = detailView.findViewById(R.id.take_cell); - TextView takeLabel = takeView.findViewById(R.id.label); - TextView takeValue = (takeView.findViewById(R.id.value)); + MaterialTextView takeLabel = takeView.findViewById(R.id.label); + TextInputEditText takeValue = (takeView.findViewById(R.id.value)); takeLabel.setText(R.string.drug_take_label); //takeValue.setText(Double.toString(prescription.getTake())); takeValue.setText(Utils.fmt(prescription.getTake())); @@ -107,8 +108,8 @@ public class DrugDetailFragment extends Fragment { takeValue.setSelectAllOnFocus(true); warningView = detailView.findViewById(R.id.warning_cell); - TextView warningLibelle = warningView.findViewById(R.id.label); - TextView warningValue = warningView.findViewById(R.id.value); + MaterialTextView warningLibelle = warningView.findViewById(R.id.label); + TextInputEditText warningValue = warningView.findViewById(R.id.value); warningLibelle.setText(R.string.drug_warningThreshold_label); //warningValue.setText(Integer.toString(prescription.getWarnThreshold())); warningValue.setText(Utils.fmt(prescription.getWarning())); @@ -116,8 +117,8 @@ public class DrugDetailFragment extends Fragment { warningValue.setSelectAllOnFocus(true); alertView = detailView.findViewById(R.id.alert_cell); - TextView alertLibelle = alertView.findViewById(R.id.label); - TextView alertValue = alertView.findViewById(R.id.value); + MaterialTextView alertLibelle = alertView.findViewById(R.id.label); + TextInputEditText alertValue = alertView.findViewById(R.id.value); alertLibelle.setText(R.string.drug_alertThreshold_label); //alertValue.setText(Integer.toString(prescription.getAlertThreshold())); alertValue.setText(Utils.fmt(prescription.getAlert())); diff --git a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java index c2b7833..da2f67b 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java @@ -27,24 +27,24 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.view.Window; -import android.widget.Button; import android.widget.EditText; -import android.widget.ImageView; -import android.widget.TextView; import android.widget.Toast; import androidx.activity.result.ActivityResultLauncher; import androidx.annotation.NonNull; -import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.RecyclerView; import androidx.room.Room; +import com.google.android.material.appbar.MaterialToolbar; +import com.google.android.material.button.MaterialButton; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.floatingactionbutton.FloatingActionButton; +import com.google.android.material.imageview.ShapeableImageView; import com.google.android.material.snackbar.Snackbar; +import com.google.android.material.textview.MaterialTextView; import com.google.zxing.client.android.BuildConfig; import com.google.zxing.client.android.Intents; import com.journeyapps.barcodescanner.ScanOptions; @@ -177,7 +177,7 @@ public class DrugListActivity extends AppCompatActivity { // Set view content setContentView(R.layout.drug_list_activity); - Toolbar toolbar = findViewById(R.id.toolbar); + MaterialToolbar toolbar = findViewById(R.id.toolbar); if (toolbar != null) { setSupportActionBar(toolbar); @@ -347,11 +347,11 @@ public class DrugListActivity extends AppCompatActivity { dialog.setCanceledOnTouchOutside(true); dialog.setContentView(R.layout.input_dialog); - Button ok = dialog.findViewById(R.id.agreed); - Button cancel = dialog.findViewById(R.id.notagreed); + MaterialButton ok = dialog.findViewById(R.id.agreed); + MaterialButton cancel = dialog.findViewById(R.id.notagreed); ok.setEnabled(false); - ok.setBackground(ContextCompat.getDrawable(this, R.drawable.rounded_btn_disabled)); - //TextView title = dialog.findViewById(R.id.title); + ok.setBackground(getDrawable(R.drawable.rounded_btn_disabled)); + //MaterialTextView title = dialog.findViewById(R.id.title); final EditText editText= dialog.findViewById(R.id.editcip13); String cip13 = String.valueOf(editText.getText()); @@ -405,12 +405,12 @@ public class DrugListActivity extends AppCompatActivity { dlg.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); dlg.setContentView(R.layout.custom_dialog_layout_one_button); dlg.setCancelable(false); - TextView msg = dlg.findViewById(R.id.msg); + MaterialTextView msg = dlg.findViewById(R.id.msg); String msgString; - TextView cpl = dlg.findViewById(R.id.cpl); + MaterialTextView cpl = dlg.findViewById(R.id.cpl); String cplString; - ImageView icon = dlg.findViewById(R.id.image); - Button btn = dlg.findViewById(R.id.txtClose); + ShapeableImageView icon = dlg.findViewById(R.id.image); + MaterialButton btn = dlg.findViewById(R.id.txtClose); dlg.show(); if (aMedicine != null) { @@ -445,7 +445,7 @@ public class DrugListActivity extends AppCompatActivity { * Tell user that the barre code cannot be interpreted */ private void scanNotOK() { - AlertDialog.Builder dlg = new AlertDialog.Builder(this); + MaterialAlertDialogBuilder dlg = new MaterialAlertDialogBuilder(this); dlg.setTitle(getString(R.string.app_name)); dlg.setMessage(R.string.notInterpreted); @@ -516,7 +516,8 @@ public class DrugListActivity extends AppCompatActivity { Snackbar.LENGTH_LONG).setAction(R.string.Undo, v -> { prescriptionList.add(position, prescription); mAdapter.notifyItemInserted(position); - }).show(); + }).setActionTextColor(getResources().getColor(R.color.bg_screen1)) + .show(); } @Override @@ -684,9 +685,9 @@ public class DrugListActivity extends AppCompatActivity { class ViewHolder extends RecyclerView.ViewHolder { final View mView; - final TextView mContentView; - final TextView mEndOfStock; - final ImageView mIconView; + final MaterialTextView mContentView; + final MaterialTextView mEndOfStock; + final ShapeableImageView mIconView; public Prescription mItem; ViewHolder(View view) { diff --git a/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java b/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java index 0f24363..1dad17e 100644 --- a/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java @@ -13,23 +13,23 @@ import android.view.Window; import android.view.WindowInsets; import android.view.WindowInsetsController; import android.view.WindowManager; -import android.widget.Button; -import android.widget.ImageView; import android.widget.LinearLayout; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.ContextCompat; import androidx.viewpager.widget.PagerAdapter; import androidx.viewpager.widget.ViewPager; +import com.google.android.material.button.MaterialButton; +import com.google.android.material.imageview.ShapeableImageView; +import com.google.android.material.textview.MaterialTextView; public class WelcomeActivity extends AppCompatActivity { private ViewPager viewPager; private LinearLayout dotsLayout; private int[] layouts; - private Button btnSkip, btnNext; + private MaterialButton btnSkip, btnNext; // viewpager change listener final ViewPager.OnPageChangeListener viewPagerPageChangeListener = new ViewPager.OnPageChangeListener() { @@ -141,12 +141,12 @@ public class WelcomeActivity extends AppCompatActivity { dlg.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); dlg.setContentView(R.layout.custom_dialog_layout_one_button); dlg.setCancelable(false); - TextView msg = dlg.findViewById(R.id.msg); + MaterialTextView msg = dlg.findViewById(R.id.msg); String msgString; - TextView cpl = dlg.findViewById(R.id.cpl); + MaterialTextView cpl = dlg.findViewById(R.id.cpl); String cplString = ""; - ImageView icon = dlg.findViewById(R.id.image); - Button btn = dlg.findViewById(R.id.txtClose); + ShapeableImageView icon = dlg.findViewById(R.id.image); + MaterialButton btn = dlg.findViewById(R.id.txtClose); dlg.show(); msgString = getString(R.string.understood); @@ -164,11 +164,11 @@ public class WelcomeActivity extends AppCompatActivity { } private void addBottomDots(int currentPage) { - TextView[] dots = new TextView[layouts.length]; + MaterialTextView[] dots = new MaterialTextView[layouts.length]; dotsLayout.removeAllViews(); for (int i = 0; i < dots.length; i++) { - dots[i] = new TextView(this); + dots[i] = new MaterialTextView(this); dots[i].setText("∙"); dots[i].setTextSize(65); dots[i].setTextColor(ContextCompat.getColor(this, R.color.dot_dark)); diff --git a/app/src/main/res/drawable/arrow_back.xml b/app/src/main/res/drawable/arrow_back.xml new file mode 100644 index 0000000..0e2e863 --- /dev/null +++ b/app/src/main/res/drawable/arrow_back.xml @@ -0,0 +1,11 @@ + + + diff --git a/app/src/main/res/layout/about.xml b/app/src/main/res/layout/about.xml index 51b7569..4087f6b 100644 --- a/app/src/main/res/layout/about.xml +++ b/app/src/main/res/layout/about.xml @@ -1,11 +1,22 @@ - + + + - -