mirror of https://github.com/M66B/FairEmail.git
Custom toast
This commit is contained in:
parent
dcc43a1f1c
commit
d488809a69
|
@ -188,10 +188,10 @@ abstract class ActivityBilling extends ActivityBase implements PurchasesUpdatedL
|
|||
.putBoolean("play_store", false)
|
||||
.apply();
|
||||
Log.i("IAB response valid");
|
||||
Toast.makeText(this, R.string.title_pro_valid, Toast.LENGTH_LONG).show();
|
||||
ToastEx.makeText(this, R.string.title_pro_valid, Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
Log.i("IAB response invalid");
|
||||
Toast.makeText(this, R.string.title_pro_invalid, Toast.LENGTH_LONG).show();
|
||||
ToastEx.makeText(this, R.string.title_pro_invalid, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} catch (NoSuchAlgorithmException ex) {
|
||||
Log.e(ex);
|
||||
|
|
|
@ -377,7 +377,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|||
Helper.unexpectedError(getSupportFragmentManager(), ex);
|
||||
}
|
||||
} else
|
||||
Toast.makeText(this, R.string.title_pro_feature, Toast.LENGTH_LONG).show();
|
||||
ToastEx.makeText(this, R.string.title_pro_feature, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
private void onMenuImport() {
|
||||
|
@ -425,7 +425,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|||
if (pro)
|
||||
prefs.edit().putBoolean("biometrics", !biometrics).apply();
|
||||
|
||||
Toast.makeText(ActivitySetup.this,
|
||||
ToastEx.makeText(ActivitySetup.this,
|
||||
pro ? R.string.title_setup_done : R.string.title_pro_feature,
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
@ -619,13 +619,13 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|||
|
||||
@Override
|
||||
protected void onExecuted(Bundle args, Void data) {
|
||||
Toast.makeText(ActivitySetup.this, R.string.title_setup_exported, Toast.LENGTH_LONG).show();
|
||||
ToastEx.makeText(ActivitySetup.this, R.string.title_setup_exported, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
if (ex instanceof IllegalArgumentException)
|
||||
Toast.makeText(ActivitySetup.this, ex.getMessage(), Toast.LENGTH_LONG).show();
|
||||
ToastEx.makeText(ActivitySetup.this, ex.getMessage(), Toast.LENGTH_LONG).show();
|
||||
else
|
||||
Helper.unexpectedError(getSupportFragmentManager(), ex);
|
||||
}
|
||||
|
@ -895,15 +895,15 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|||
|
||||
@Override
|
||||
protected void onExecuted(Bundle args, Void data) {
|
||||
Toast.makeText(ActivitySetup.this, R.string.title_setup_imported, Toast.LENGTH_LONG).show();
|
||||
ToastEx.makeText(ActivitySetup.this, R.string.title_setup_imported, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
if (ex.getCause() instanceof BadPaddingException)
|
||||
Toast.makeText(ActivitySetup.this, R.string.title_setup_password_invalid, Toast.LENGTH_LONG).show();
|
||||
ToastEx.makeText(ActivitySetup.this, R.string.title_setup_password_invalid, Toast.LENGTH_LONG).show();
|
||||
else if (ex instanceof IllegalArgumentException)
|
||||
Toast.makeText(ActivitySetup.this, ex.getMessage(), Toast.LENGTH_LONG).show();
|
||||
ToastEx.makeText(ActivitySetup.this, ex.getMessage(), Toast.LENGTH_LONG).show();
|
||||
else
|
||||
Helper.unexpectedError(getSupportFragmentManager(), ex);
|
||||
}
|
||||
|
@ -1055,7 +1055,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|||
String password2 = etPassword2.getEditText().getText().toString();
|
||||
|
||||
if (!BuildConfig.DEBUG && TextUtils.isEmpty(password1))
|
||||
Toast.makeText(getContext(), R.string.title_setup_password_missing, Toast.LENGTH_LONG).show();
|
||||
ToastEx.makeText(getContext(), R.string.title_setup_password_missing, Toast.LENGTH_LONG).show();
|
||||
else {
|
||||
if (!export || password1.equals(password2)) {
|
||||
((ActivitySetup) getActivity()).password = password1;
|
||||
|
@ -1064,7 +1064,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|||
export ? getIntentExport() : getIntentImport()),
|
||||
export ? REQUEST_EXPORT : REQUEST_IMPORT);
|
||||
} else
|
||||
Toast.makeText(getContext(), R.string.title_setup_password_different, Toast.LENGTH_LONG).show();
|
||||
ToastEx.makeText(getContext(), R.string.title_setup_password_different, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -532,7 +532,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
|||
super.onBackPressed();
|
||||
else {
|
||||
exit = true;
|
||||
Toast.makeText(this, R.string.app_exit, Toast.LENGTH_SHORT).show();
|
||||
ToastEx.makeText(this, R.string.app_exit, Toast.LENGTH_SHORT).show();
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -616,7 +616,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
|||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Toast.makeText(ActivityView.this,
|
||||
ToastEx.makeText(ActivityView.this,
|
||||
Helper.formatThrowable(ex, false), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}.execute(this, new Bundle(), "crash:log");
|
||||
|
@ -711,7 +711,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
|||
boolean always = args.getBoolean("always");
|
||||
if (info == null) {
|
||||
if (always)
|
||||
Toast.makeText(ActivityView.this, BuildConfig.VERSION_NAME, Toast.LENGTH_LONG).show();
|
||||
ToastEx.makeText(ActivityView.this, BuildConfig.VERSION_NAME, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -740,7 +740,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
|||
protected void onException(Bundle args, Throwable ex) {
|
||||
if (args.getBoolean("always"))
|
||||
if (ex instanceof IllegalArgumentException || ex instanceof IOException)
|
||||
Toast.makeText(ActivityView.this, ex.getMessage(), Toast.LENGTH_LONG).show();
|
||||
ToastEx.makeText(ActivityView.this, ex.getMessage(), Toast.LENGTH_LONG).show();
|
||||
else
|
||||
Helper.unexpectedError(getSupportFragmentManager(), ex);
|
||||
}
|
||||
|
@ -887,9 +887,9 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
|||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
if (ex instanceof IllegalArgumentException)
|
||||
Toast.makeText(ActivityView.this, ex.getMessage(), Toast.LENGTH_LONG).show();
|
||||
ToastEx.makeText(ActivityView.this, ex.getMessage(), Toast.LENGTH_LONG).show();
|
||||
else
|
||||
Toast.makeText(ActivityView.this, ex.toString(), Toast.LENGTH_LONG).show();
|
||||
ToastEx.makeText(ActivityView.this, ex.toString(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
}.execute(this, new Bundle(), "debug:info");
|
||||
|
|
|
@ -1290,7 +1290,7 @@ public class FragmentAccount extends FragmentBase {
|
|||
Bundle args = data.getBundleExtra("args");
|
||||
setColor(args.getInt("color"));
|
||||
} else
|
||||
Toast.makeText(getContext(), R.string.title_pro_feature, Toast.LENGTH_LONG).show();
|
||||
ToastEx.makeText(getContext(), R.string.title_pro_feature, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
break;
|
||||
case REQUEST_SAVE:
|
||||
|
|
|
@ -2609,7 +2609,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
Handler handler = new Handler(context.getMainLooper());
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
Toast.makeText(context, R.string.title_draft_deleted, Toast.LENGTH_LONG).show();
|
||||
ToastEx.makeText(context, R.string.title_draft_deleted, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -2623,7 +2623,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
Handler handler = new Handler(context.getMainLooper());
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
Toast.makeText(context, R.string.title_draft_saved, Toast.LENGTH_LONG).show();
|
||||
ToastEx.makeText(context, R.string.title_draft_saved, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -2684,7 +2684,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
Handler handler = new Handler(context.getMainLooper());
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
Toast.makeText(context, feedback, Toast.LENGTH_LONG).show();
|
||||
ToastEx.makeText(context, feedback, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1032,7 +1032,7 @@ public class FragmentIdentity extends FragmentBase {
|
|||
Bundle args = data.getBundleExtra("args");
|
||||
setColor(args.getInt("color"));
|
||||
} else
|
||||
Toast.makeText(getContext(), R.string.title_pro_feature, Toast.LENGTH_LONG).show();
|
||||
ToastEx.makeText(getContext(), R.string.title_pro_feature, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
break;
|
||||
case REQUEST_SAVE:
|
||||
|
|
|
@ -271,7 +271,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
|||
|
||||
@Override
|
||||
protected void onExecuted(Bundle args, Void data) {
|
||||
Toast.makeText(getContext(), R.string.title_setup_done, Toast.LENGTH_LONG).show();
|
||||
ToastEx.makeText(getContext(), R.string.title_setup_done, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -218,10 +218,10 @@ public class Helper {
|
|||
customTabsIntent.launchUrl(context, uri);
|
||||
} catch (ActivityNotFoundException ex) {
|
||||
Log.w(ex);
|
||||
Toast.makeText(context, context.getString(R.string.title_no_viewer, uri.toString()), Toast.LENGTH_LONG).show();
|
||||
ToastEx.makeText(context, context.getString(R.string.title_no_viewer, uri.toString()), Toast.LENGTH_LONG).show();
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
Toast.makeText(context, Helper.formatThrowable(ex, false), Toast.LENGTH_LONG).show();
|
||||
ToastEx.makeText(context, Helper.formatThrowable(ex, false), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -489,9 +489,9 @@ public class Helper {
|
|||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
if (ex instanceof IllegalArgumentException)
|
||||
Toast.makeText(context, ex.getMessage(), Toast.LENGTH_LONG).show();
|
||||
ToastEx.makeText(context, ex.getMessage(), Toast.LENGTH_LONG).show();
|
||||
else
|
||||
Toast.makeText(context, ex.toString(), Toast.LENGTH_LONG).show();
|
||||
ToastEx.makeText(context, ex.toString(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}.execute(context, getActivity(), new Bundle(), "error:unexpected");
|
||||
}
|
||||
|
@ -722,7 +722,7 @@ public class Helper {
|
|||
errorCode == BiometricPrompt.ERROR_USER_CANCELED)
|
||||
cancelled.run();
|
||||
else
|
||||
Toast.makeText(activity,
|
||||
ToastEx.makeText(activity,
|
||||
errString + " (" + errorCode + ")",
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
@ -751,7 +751,7 @@ public class Helper {
|
|||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(activity,
|
||||
ToastEx.makeText(activity,
|
||||
R.string.title_unexpected_error,
|
||||
Toast.LENGTH_LONG).show();
|
||||
cancelled.run();
|
||||
|
|
|
@ -100,7 +100,7 @@ public class Shortcuts {
|
|||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Toast.makeText(context, Helper.formatThrowable(ex, false), Toast.LENGTH_LONG).show();
|
||||
ToastEx.makeText(context, Helper.formatThrowable(ex, false), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}.execute(context, owner, new Bundle(), "shortcuts:update");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package eu.faircode.email;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class ToastEx {
|
||||
public static Toast makeText(Context context, int resId, int duration) throws Resources.NotFoundException {
|
||||
return makeText(context, context.getText(resId), duration);
|
||||
}
|
||||
|
||||
public static Toast makeText(Context context, CharSequence text, int duration) {
|
||||
Toast toast = new Toast(context);
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
View view = inflater.inflate(R.layout.toast, null);
|
||||
TextView tv = view.findViewById(android.R.id.message);
|
||||
tv.setText(text);
|
||||
toast.setView(view);
|
||||
toast.setDuration(duration);
|
||||
return toast;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<corners android:radius="12dp" />
|
||||
<stroke
|
||||
android:width="1dp"
|
||||
android:color="?colorPrimary" />
|
||||
<solid android:color="?colorPrimary" />
|
||||
</shape>
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/toast_background"
|
||||
android:orientation="vertical"
|
||||
android:padding="9dp">
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/message"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="Message"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
android:textColor="@android:color/white" />
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue