Navigation Menu

Skip to content

Commit

Permalink
Create custom layout files for indeterminate/determinate progress ind…
Browse files Browse the repository at this point in the history
…icators
  • Loading branch information
t895 committed Aug 15, 2022
1 parent 0fc34c9 commit bad9755
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 37 deletions.
Expand Up @@ -9,7 +9,6 @@
import android.provider.Settings;
import android.view.Menu;
import android.view.MenuInflater;
import android.widget.ProgressBar;
import android.widget.Toast;

import androidx.annotation.NonNull;
Expand Down Expand Up @@ -218,17 +217,10 @@ public void showLoading()
{
if (dialog == null)
{
ProgressBar progressBar =
new ProgressBar(this, null, android.R.attr.progressBarStyle);
final int dpHorizontal = 24;
final int dpVertical = 16;
int pxHorizontal = ThemeHelper.dpToPx(dpHorizontal, getResources());
int pxVertical = ThemeHelper.dpToPx(dpVertical, getResources());
progressBar.setPadding(pxHorizontal, pxVertical, pxHorizontal, pxVertical);

dialog = new MaterialAlertDialogBuilder(this)
.setTitle(getString(R.string.load_settings))
.setView(progressBar)
.setView(getLayoutInflater().inflate(R.layout.dialog_indeterminate_progress, null,
false))
.create();
}
dialog.show();
Expand Down
Expand Up @@ -5,7 +5,7 @@
import android.app.Dialog;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.widget.ProgressBar;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand All @@ -14,9 +14,9 @@
import androidx.lifecycle.ViewModelProvider;

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

import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.utils.ThemeHelper;

public class SystemUpdateProgressBarDialogFragment extends DialogFragment
{
Expand All @@ -32,20 +32,15 @@ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState)
SystemUpdateViewModel viewModel =
new ViewModelProvider(requireActivity()).get(SystemUpdateViewModel.class);

ProgressBar progressBar =
new ProgressBar(requireContext(), null, android.R.attr.progressBarStyleHorizontal);
final int dpHorizontal = 24;
final int dpVertical = 16;
int pxHorizontal = ThemeHelper.dpToPx(dpHorizontal, getResources());
int pxVertical = ThemeHelper.dpToPx(dpVertical, getResources());
progressBar.setPadding(pxHorizontal, pxVertical, pxHorizontal, pxVertical);
View dialogView = getLayoutInflater().inflate(R.layout.dialog_progress, null, false);
LinearProgressIndicator progressBar = dialogView.findViewById(R.id.update_progress);

// We need to set the message to something here, otherwise the text will not appear when we set it later.
AlertDialog progressDialog = new MaterialAlertDialogBuilder(requireContext())
.setTitle(getString(R.string.updating))
.setMessage("")
.setNegativeButton(getString(R.string.cancel), null)
.setView(progressBar)
.setView(dialogView)
.create();

viewModel.getProgressData().observe(this, (@Nullable Integer progress) ->
Expand Down
Expand Up @@ -14,7 +14,6 @@
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ProgressBar;
import android.widget.Spinner;

import androidx.annotation.NonNull;
Expand All @@ -23,14 +22,13 @@
import androidx.fragment.app.Fragment;

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

import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.model.GameFile;
import org.dolphinemu.dolphinemu.services.GameFileCacheManager;
import org.dolphinemu.dolphinemu.ui.platform.Platform;
import org.dolphinemu.dolphinemu.utils.Log;
import org.dolphinemu.dolphinemu.utils.ThemeHelper;

import java.io.File;
import java.util.ArrayList;
Expand Down Expand Up @@ -425,21 +423,15 @@ private void convert(String outPath)

mCanceled = false;

ProgressBar progressBar =
new ProgressBar(context, null, android.R.attr.progressBarStyleHorizontal);
final int dpHorizontal = 24;
final int dpVertical = 24;
int pxHorizontal = ThemeHelper.dpToPx(dpHorizontal, getResources());
int pxVertical = ThemeHelper.dpToPx(dpVertical, getResources());
progressBar.setPadding(pxHorizontal, pxVertical, pxHorizontal, 0);
View dialogView = getLayoutInflater().inflate(R.layout.dialog_progress, null, false);
LinearProgressIndicator progressBar = dialogView.findViewById(R.id.update_progress);
progressBar.setMax(PROGRESS_RESOLUTION);

AlertDialog progressDialog = new MaterialAlertDialogBuilder(context)
.setTitle(R.string.convert_converting)
.setCancelable(true)
.setOnCancelListener((dialog) -> mCanceled = true)
.setNegativeButton(getString(R.string.cancel), (dialog, i) -> dialog.dismiss())
.setView(progressBar)
.setView(dialogView)
.show();

mThread = new Thread(() ->
Expand Down
Expand Up @@ -117,9 +117,4 @@ public static void checkThemeSetting(Activity activity)
activity.recreate();
}
}

public static int dpToPx(float dp, Resources resources)
{
return (int) (dp * resources.getDisplayMetrics().density + 0.5f);
}
}
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.google.android.material.progressindicator.CircularProgressIndicator
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_margin="16dp"
android:indeterminate="true"
app:trackCornerRadius="2dp" />

</RelativeLayout>
18 changes: 18 additions & 0 deletions Source/Android/app/src/main/res/layout/dialog_progress.xml
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/dialog_progress"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.google.android.material.progressindicator.LinearProgressIndicator
android:id="@+id/update_progress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
app:trackCornerRadius="2dp" />

</androidx.appcompat.widget.LinearLayoutCompat>

0 comments on commit bad9755

Please sign in to comment.