2017-11-24 22:00:30 -08:00
|
|
|
package org.thoughtcrime.securesms.permissions;
|
|
|
|
|
|
|
|
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.graphics.Color;
|
2019-06-05 15:47:14 -04:00
|
|
|
import androidx.annotation.DrawableRes;
|
|
|
|
import androidx.annotation.NonNull;
|
2019-10-07 15:43:36 -03:00
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
|
import androidx.core.graphics.drawable.DrawableCompat;
|
|
|
|
|
|
|
|
import android.graphics.drawable.Drawable;
|
2017-11-24 22:00:30 -08:00
|
|
|
import android.util.TypedValue;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout.LayoutParams;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.R;
|
2019-11-14 13:51:01 -05:00
|
|
|
import org.thoughtcrime.securesms.util.ThemeUtil;
|
2017-11-24 22:00:30 -08:00
|
|
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
|
|
|
|
|
|
|
public class RationaleDialog {
|
|
|
|
|
|
|
|
public static AlertDialog.Builder createFor(@NonNull Context context, @NonNull String message, @DrawableRes int... drawables) {
|
|
|
|
View view = LayoutInflater.from(context).inflate(R.layout.permissions_rationale_dialog, null);
|
|
|
|
ViewGroup header = view.findViewById(R.id.header_container);
|
|
|
|
TextView text = view.findViewById(R.id.message);
|
|
|
|
|
|
|
|
for (int i=0;i<drawables.length;i++) {
|
2019-10-07 15:43:36 -03:00
|
|
|
Drawable drawable = ContextCompat.getDrawable(context, drawables[i]);
|
|
|
|
DrawableCompat.setTint(drawable, ContextCompat.getColor(context, R.color.white));
|
2017-11-24 22:00:30 -08:00
|
|
|
ImageView imageView = new ImageView(context);
|
2019-10-07 15:43:36 -03:00
|
|
|
imageView.setImageDrawable(drawable);
|
2017-11-24 22:00:30 -08:00
|
|
|
imageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
|
|
|
|
|
|
|
|
header.addView(imageView);
|
|
|
|
|
|
|
|
if (i != drawables.length - 1) {
|
|
|
|
TextView plus = new TextView(context);
|
|
|
|
plus.setText("+");
|
|
|
|
plus.setTextSize(TypedValue.COMPLEX_UNIT_SP, 40);
|
|
|
|
plus.setTextColor(Color.WHITE);
|
|
|
|
|
|
|
|
LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
|
|
|
layoutParams.setMargins(ViewUtil.dpToPx(context, 20), 0, ViewUtil.dpToPx(context, 20), 0);
|
|
|
|
|
|
|
|
plus.setLayoutParams(layoutParams);
|
|
|
|
header.addView(plus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
text.setText(message);
|
|
|
|
|
2019-11-14 13:51:01 -05:00
|
|
|
return new AlertDialog.Builder(context, ThemeUtil.isDarkTheme(context) ? R.style.RationaleDialogDark : R.style.RationaleDialogLight)
|
|
|
|
.setView(view);
|
2017-11-24 22:00:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|