Index: mobile/android/base/java/org/adblockplus/browser/FeedbackPreference.java |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/mobile/android/base/java/org/adblockplus/browser/FeedbackPreference.java |
@@ -0,0 +1,90 @@ |
+/* |
+ * This file is part of Adblock Plus <https://adblockplus.org/>, |
+ * Copyright (C) 2006-present eyeo GmbH |
+ * |
+ * Adblock Plus is free software: you can redistribute it and/or modify |
+ * it under the terms of the GNU General Public License version 3 as |
+ * published by the Free Software Foundation. |
+ * |
+ * Adblock Plus is distributed in the hope that it will be useful, |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+ * GNU General Public License for more details. |
+ * |
+ * You should have received a copy of the GNU General Public License |
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
+ */ |
+ |
+package org.adblockplus.browser; |
+ |
+import android.content.Context; |
+import android.content.Intent; |
+import android.content.pm.PackageInfo; |
+import android.content.pm.PackageManager; |
+import android.content.res.Resources; |
+import android.net.Uri; |
+import android.os.Build; |
+import android.preference.Preference; |
+import android.util.AttributeSet; |
+ |
+public class FeedbackPreference extends Preference |
+{ |
+ private static final String EMAIL_RECIPIENT = "support@adblockplus.org"; |
+ private static final String EMAIL_SUBJECT = "Feedback - Adblock Browser for Android"; |
+ |
+ public FeedbackPreference(Context context) |
+ { |
+ super(context); |
+ } |
+ |
+ public FeedbackPreference(Context context, AttributeSet attrs) |
+ { |
+ super(context, attrs); |
+ } |
+ |
+ public FeedbackPreference(Context context, AttributeSet attrs, int defStyle) |
+ { |
+ super(context, attrs, defStyle); |
+ } |
+ |
+ @Override |
+ protected void onClick() |
+ { |
+ final String emailBody = generateEmailBody(); |
+ final Intent intent = new Intent(Intent.ACTION_VIEW); |
+ final Uri data = Uri.parse( |
+ "mailto:" + EMAIL_RECIPIENT + "?subject=" + EMAIL_SUBJECT + "&body=" + emailBody); |
+ intent.setData(data); |
+ getContext().startActivity(intent); |
anton
2019/02/26 12:52:54
do we assume email client is always installed? oth
diegocarloslima
2019/02/27 16:37:57
I don't think that an exception will ever occur, b
|
+ } |
+ |
+ private String generateEmailBody() |
+ { |
+ String emailBody = "\n\n\nUseful information:"; |
+ emailBody += "\n App Version: " + getAppVersion(); |
+ emailBody += "\n Android Version: " + Build.VERSION.RELEASE; |
+ emailBody += "\n Device Model: " + Build.MANUFACTURER + " - " + Build.MODEL; |
+ emailBody += "\n Language: " + getLanguage(); |
+ return emailBody; |
+ } |
+ |
+ private String getAppVersion() |
+ { |
+ try |
+ { |
+ final PackageInfo packageInfo = getContext().getPackageManager().getPackageInfo( |
+ getContext().getPackageName(), 0); |
+ return packageInfo.versionName; |
+ } |
+ catch (PackageManager.NameNotFoundException e) |
+ { |
+ } |
+ return ""; |
+ } |
+ |
+ private String getLanguage() |
+ { |
+ // TODO: Replace by ConfigurationCompat when the support lib is >= 26.1.0 |
anton
2019/02/26 12:52:54
afaik somewhere in code style guide there is requi
diegocarloslima
2019/02/27 16:37:57
Acknowledged.
|
+ return Resources.getSystem().getConfiguration().locale.toString(); |
+ } |
+} |