summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael W <baddaemon87@gmail.com>2021-03-13 15:06:04 +0100
committerMichael W <baddaemon87@gmail.com>2021-03-14 16:56:17 +0100
commit21bf85c4859bbd25242fd5f377154855a53b39cb (patch)
tree37c05f489c776b567a1062995f278b38c4ad7a87
parent62924a3cf27ec62e6bfa2d128f5659559ac8c55f (diff)
Dialer: Add a helpline phone book
* Expose the sensitive numbers to the user so they can easily call one of them * Make sure to leave as few traces of access as possible: * Calling a number closes the helpline activity * Opening a link closes the helpline activity * Before opening a link, a warning about browser history appears * This makes use of a changed xml-format, which now allows adding various things: <item> <categories>violence|human trafficking</categories> <name>Some NGO or whatever</name> <number>1234</number> <anything>anything else</anything> </item> Change-Id: I952bf10ee9516b83e595d8a19450696b303393b6
-rw-r--r--Android.mk1
-rw-r--r--java/com/android/dialer/app/res/values/cm_strings.xml4
-rw-r--r--java/com/android/dialer/helplines/AndroidManifest.xml36
-rwxr-xr-xjava/com/android/dialer/helplines/HelplineActivity.java245
-rw-r--r--java/com/android/dialer/helplines/HelplineAdapter.java158
-rw-r--r--java/com/android/dialer/helplines/HelplineItem.java40
-rw-r--r--java/com/android/dialer/helplines/LoadHelplinesTask.java121
-rw-r--r--java/com/android/dialer/helplines/res/drawable/ic_help.xml26
-rw-r--r--java/com/android/dialer/helplines/res/drawable/ic_helpline_call.xml25
-rw-r--r--java/com/android/dialer/helplines/res/layout/activity_helplines.xml70
-rw-r--r--java/com/android/dialer/helplines/res/layout/dialog_helpline_details.xml105
-rw-r--r--java/com/android/dialer/helplines/res/layout/item_helpline.xml80
-rw-r--r--java/com/android/dialer/helplines/res/menu/menu_helplines.xml23
-rw-r--r--java/com/android/dialer/helplines/res/values/dimens.xml20
-rw-r--r--java/com/android/dialer/helplines/res/values/helpline_categories.xml64
-rw-r--r--java/com/android/dialer/helplines/res/values/helpline_names.xml19
-rw-r--r--java/com/android/dialer/helplines/res/values/strings.xml49
-rwxr-xr-xjava/com/android/dialer/helplines/res/values/styles.xml39
-rw-r--r--java/com/android/dialer/helplines/utils/HelplineUtils.java91
-rw-r--r--java/com/android/dialer/helplines/utils/ResourceUtils.java54
-rw-r--r--java/com/android/dialer/main/impl/MainSearchController.java3
-rw-r--r--java/com/android/dialer/main/impl/toolbar/res/menu/main_menu.xml5
22 files changed, 1277 insertions, 1 deletions
diff --git a/Android.mk b/Android.mk
index db6cff7bd..4e92f1f38 100644
--- a/Android.mk
+++ b/Android.mk
@@ -133,6 +133,7 @@ LOCAL_STATIC_JAVA_LIBRARIES := \
libbackup \
libphonenumber \
volley \
+ org.lineageos.lib.phone
LOCAL_STATIC_ANDROID_LIBRARIES := \
android-support-core-ui \
diff --git a/java/com/android/dialer/app/res/values/cm_strings.xml b/java/com/android/dialer/app/res/values/cm_strings.xml
index 1dcdb2b81..84d6ef735 100644
--- a/java/com/android/dialer/app/res/values/cm_strings.xml
+++ b/java/com/android/dialer/app/res/values/cm_strings.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2013-2014 The CyanogenMod Project
- Copyright (C) 2018 The LineageOS Project
+ Copyright (C) 2018-2021 The LineageOS Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -43,4 +43,6 @@
<string name="call_via_dialog_title">Call via\u2026</string>
<string name="call_log_stats_title">Statistics</string>
+
+ <string name="action_menu_helplines">Helplines</string>
</resources>
diff --git a/java/com/android/dialer/helplines/AndroidManifest.xml b/java/com/android/dialer/helplines/AndroidManifest.xml
new file mode 100644
index 000000000..45706cdad
--- /dev/null
+++ b/java/com/android/dialer/helplines/AndroidManifest.xml
@@ -0,0 +1,36 @@
+<!--
+ Copyright (C) 2019-2021 The LineageOS Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License
+ -->
+<manifest
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.dialer.helplines">
+
+ <application>
+
+ <activity
+ android:name=".HelplineActivity"
+ android:autoRemoveFromRecents="true"
+ android:label="@string/helplines_name"
+ android:theme="@android:style/Theme.DeviceDefault.Settings"
+ android:excludeFromRecents="true">
+ <intent-filter>
+ <action android:name="android.intent.action.VIEW" />
+ <category android:name="android.intent.category.DEFAULT"/>
+ <data android:scheme="header"/>
+ </intent-filter>
+ </activity>
+ </application>
+
+</manifest>
diff --git a/java/com/android/dialer/helplines/HelplineActivity.java b/java/com/android/dialer/helplines/HelplineActivity.java
new file mode 100755
index 000000000..906b6fd2c
--- /dev/null
+++ b/java/com/android/dialer/helplines/HelplineActivity.java
@@ -0,0 +1,245 @@
+/*
+ * Copyright (C) 2019-2021 The LineageOS Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.dialer.helplines;
+
+import android.app.ActionBar;
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.Context;
+import android.content.Intent;
+import android.content.res.Resources;
+import android.content.SharedPreferences;
+import android.net.Uri;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.telephony.SubscriptionManager;
+import android.text.TextUtils;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.LinearLayout;
+import android.widget.ProgressBar;
+import android.widget.TextView;
+
+import com.android.dialer.R;
+import com.android.dialer.app.calllog.IntentProvider;
+import com.android.dialer.helplines.utils.HelplineUtils;
+
+import java.util.List;
+
+import static android.graphics.Paint.UNDERLINE_TEXT_FLAG;
+
+public class HelplineActivity extends Activity {
+
+ public static final String SHARED_PREFERENCES_KEY = "com.android.dialer.prefs";
+
+ private static final String KEY_FIRST_LAUNCH = "pref_first_launch";
+
+ private RecyclerView mRecyclerView;
+ private LinearLayout mLoadingView;
+ private LinearLayout mEmptyView;
+ private ProgressBar mProgressBar;
+
+ private HelplineAdapter mAdapter;
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstance) {
+ super.onCreate(savedInstance);
+
+ ActionBar actionBar = getActionBar();
+ if (actionBar != null) {
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ }
+
+ setContentView(R.layout.activity_helplines);
+ mRecyclerView = findViewById(R.id.helplines_list);
+ mLoadingView = findViewById(R.id.helplines_loading);
+ mEmptyView = findViewById(R.id.empty_view);
+ mProgressBar = findViewById(R.id.helplines_progress_bar);
+
+ mAdapter = new HelplineAdapter(getResources(), mListener);
+
+ mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
+ mRecyclerView.setAdapter(mAdapter);
+
+ showUi();
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ finish();
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuInflater menuInflater = getMenuInflater();
+ menuInflater.inflate(R.menu.menu_helplines, menu);
+ return super.onCreateOptionsMenu(menu);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ int id = item.getItemId();
+ if (id == android.R.id.home) {
+ finish();
+ return true;
+ } else if (id == R.id.menu_helpline_help) {
+ showHelp(true);
+ return true;
+ }
+
+ return super.onOptionsItemSelected(item);
+ }
+
+ private void showUi() {
+ mLoadingView.setVisibility(View.VISIBLE);
+
+ showHelp(false);
+ SubscriptionManager subManager = getSystemService(SubscriptionManager.class);
+ new LoadHelplinesTask(getResources(), subManager, mCallback).execute();
+ }
+
+ private void showHelp(boolean forceShow) {
+ SharedPreferences preferenceManager = getPrefs();
+ if (!forceShow && preferenceManager.getBoolean(KEY_FIRST_LAUNCH, false)) {
+ return;
+ }
+
+ preferenceManager.edit()
+ .putBoolean(KEY_FIRST_LAUNCH, true)
+ .apply();
+
+ new AlertDialog.Builder(this)
+ .setTitle(R.string.helplines_help_title)
+ .setMessage(R.string.helplines_help_message)
+ .setPositiveButton(android.R.string.ok, null)
+ .setNeutralButton(R.string.helpline_button_more, (dialog, which) -> {
+ showMoreInfo(); })
+ .show();
+ }
+
+ private void showMoreInfo() {
+ new AlertDialog.Builder(this)
+ .setMessage(R.string.helplines_help_more_message)
+ .setPositiveButton(android.R.string.ok, null)
+ .show();
+ }
+
+ public SharedPreferences getPrefs() {
+ return this.getSharedPreferences(SHARED_PREFERENCES_KEY,
+ Context.MODE_PRIVATE);
+ }
+
+ private LoadHelplinesTask.Callback mCallback = new LoadHelplinesTask.Callback () {
+ @Override
+ public void onLoadListProgress(int progress) {
+ mProgressBar.setProgress(progress);
+ }
+
+ @Override
+ public void onLoadCompleted(List<HelplineItem> result) {
+ mLoadingView.setVisibility(View.GONE);
+ if (result.size() == 0) {
+ mEmptyView.setVisibility(View.VISIBLE);
+ } else {
+ mRecyclerView.setVisibility(View.VISIBLE);
+ }
+ mAdapter.update(result);
+ }
+ };
+
+ private HelplineAdapter.Listener mListener = new HelplineAdapter.Listener() {
+ private AlertDialog mDialog;
+
+ @Override
+ public void initiateCall(@NonNull String number) {
+ IntentProvider provider = IntentProvider.getReturnCallIntentProvider(number);
+ Intent intent = provider.getClickIntent(HelplineActivity.this);
+ // Start the call and finish this activity - we don't want to leave traces of the call
+ startActivity(intent);
+ finish();
+ }
+
+ @Override
+ public void onItemClicked(@NonNull HelplineItem item) {
+ LayoutInflater inflater = LayoutInflater.from(HelplineActivity.this);
+ final View dialogView = inflater.inflate(R.layout.dialog_helpline_details, null);
+
+ fillOrHideDialogRow(item.getName(), dialogView, R.id.name_title, R.id.name);
+ fillOrHideDialogRow(item.get("organization"), dialogView, R.id.org_title, R.id.org);
+ fillOrHideDialogRow(HelplineUtils.getCategories(getResources(), item),
+ dialogView, R.id.categories_title, R.id.categories);
+ fillOrHideDialogRow(item.get("number"), dialogView, R.id.number_title, R.id.number);
+ fillOrHideDialogRow(item.get("website"), dialogView, R.id.website_title, R.id.website,
+ true);
+
+ mDialog = new AlertDialog.Builder(HelplineActivity.this)
+ .setView(dialogView)
+ .setPositiveButton(android.R.string.ok, null)
+ .show();
+ }
+
+ private void fillOrHideDialogRow(String content, View dialog, int headerViewId,
+ int contentViewId) {
+ fillOrHideDialogRow(content, dialog, headerViewId, contentViewId, false);
+ }
+
+ private void fillOrHideDialogRow(String content, View dialogView, int headerViewId,
+ int contentViewId, boolean isUrl) {
+ if (dialogView == null) {
+ return;
+ }
+ TextView headerView = dialogView.findViewById(headerViewId);
+ TextView contentView = dialogView.findViewById(contentViewId);
+ if (headerView == null || contentView == null) {
+ return;
+ }
+ if (TextUtils.isEmpty(content)) {
+ headerView.setVisibility(View.GONE);
+ contentView.setVisibility(View.GONE);
+ return;
+ }
+
+ contentView.setText(content);
+ if (isUrl) {
+ contentView.setPaintFlags(contentView.getPaintFlags() | UNDERLINE_TEXT_FLAG);
+ // We want to warn the user that visiting a link might leave traces
+ contentView.setOnClickListener(v -> {
+ new AlertDialog.Builder(HelplineActivity.this)
+ .setTitle(R.string.helpline_browser_history_title)
+ .setMessage(R.string.helpline_browser_history_message)
+ .setPositiveButton(android.R.string.ok, (dlg, which) -> {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse(content));
+ mDialog.dismiss();
+ dlg.dismiss();
+ startActivity(i);
+ finish(); // Finish this activity to get rid of own traces
+ })
+ .setNegativeButton(android.R.string.cancel, null)
+ .show();
+ }
+ );
+ }
+ }
+ };
+}
diff --git a/java/com/android/dialer/helplines/HelplineAdapter.java b/java/com/android/dialer/helplines/HelplineAdapter.java
new file mode 100644
index 000000000..6dd748e9b
--- /dev/null
+++ b/java/com/android/dialer/helplines/HelplineAdapter.java
@@ -0,0 +1,158 @@
+/*
+ * Copyright (C) 2019-2021 The LineageOS Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.dialer.helplines;
+
+import android.content.res.Resources;
+import android.support.annotation.NonNull;
+import android.support.v7.util.DiffUtil;
+import android.support.v7.widget.RecyclerView;
+import android.text.TextUtils;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.android.dialer.R;
+import com.android.dialer.helplines.utils.HelplineUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+class HelplineAdapter extends RecyclerView.Adapter<HelplineAdapter.ViewHolder> {
+
+ private Resources mResources;
+ private List<HelplineItem> mList = new ArrayList<>();
+ private Listener mListener;
+
+ HelplineAdapter(Resources resources, Listener listener) {
+ mResources = resources;
+ mListener = listener;
+ }
+
+ public void update(List<HelplineItem> list) {
+ DiffUtil.DiffResult result = DiffUtil.calculateDiff(new Callback(mList, list));
+ mList = list;
+ result.dispatchUpdatesTo(this);
+ }
+
+ @NonNull
+ @Override
+ public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int type) {
+ return new ViewHolder(LayoutInflater.from(parent.getContext())
+ .inflate(R.layout.item_helpline, parent, false));
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
+ viewHolder.bind(mList.get(i));
+ }
+
+ @Override
+ public int getItemCount() {
+ return mList.size();
+ }
+
+ public interface Listener {
+ void initiateCall(@NonNull String number);
+
+ void onItemClicked(@NonNull HelplineItem item);
+ }
+
+ private static class Callback extends DiffUtil.Callback {
+ List<HelplineItem> mOldList;
+ List<HelplineItem> mNewList;
+
+ public Callback(List<HelplineItem> oldList,
+ List<HelplineItem> newList) {
+ mOldList = oldList;
+ mNewList = newList;
+ }
+
+ @Override
+ public int getOldListSize() {
+ return mOldList.size();
+ }
+
+ @Override
+ public int getNewListSize() {
+ return mNewList.size();
+ }
+
+ @Override
+ public boolean areItemsTheSame(int iOld, int iNew) {
+ String oldNumber = mOldList.get(iOld).get("number");
+ String newNumber = mOldList.get(iNew).get("number");
+ return oldNumber.equals(newNumber);
+ }
+
+ @Override
+ public boolean areContentsTheSame(int iOld, int iNew) {
+ return false;
+ }
+ }
+
+ class ViewHolder extends RecyclerView.ViewHolder {
+ private final View mItemView;
+ private final TextView mLabelView;
+ private final TextView mCategoriesView;
+ private final TextView mLanguageView;
+ private final ImageView mCallIcon;
+
+ ViewHolder(@NonNull View itemView) {
+ super(itemView);
+
+ mItemView = itemView;
+ mLabelView = itemView.findViewById(R.id.item_helpline_title);
+ mCategoriesView = itemView.findViewById(R.id.item_helpline_categories);
+ mLanguageView = itemView.findViewById(R.id.item_helpline_languages);
+ mCallIcon = itemView.findViewById(R.id.item_helpline_call_icon);
+ }
+
+ void bind(HelplineItem item) {
+ mItemView.setOnClickListener(v -> {
+ mListener.onItemClicked(item);
+ });
+
+ String name = item.getName();
+ if (!TextUtils.isEmpty(name)) {
+ mLabelView.setText(name);
+ } else {
+ mLabelView.setText(R.string.unknown_helpline_name);
+ }
+
+ String categories = HelplineUtils.getCategories(mResources, item);
+ if (!TextUtils.isEmpty(categories)) {
+ mCategoriesView.setText(categories);
+ mCategoriesView.setVisibility(View.VISIBLE);
+ }
+
+ String languages = HelplineUtils.getLanguages(mResources, item);
+ if (!TextUtils.isEmpty(languages)) {
+ mLanguageView.setVisibility(View.VISIBLE);
+ mLanguageView.setText(languages);
+ }
+
+ String number = item.get("number");
+ if (!TextUtils.isEmpty(number)) {
+ mCallIcon.setVisibility(View.VISIBLE);
+ mCallIcon.setOnClickListener(v -> {
+ mListener.initiateCall(number);
+ });
+ }
+ }
+ }
+}
diff --git a/java/com/android/dialer/helplines/HelplineItem.java b/java/com/android/dialer/helplines/HelplineItem.java
new file mode 100644
index 000000000..8ac4cc969
--- /dev/null
+++ b/java/com/android/dialer/helplines/HelplineItem.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2019-2021 The LineageOS Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.dialer.helplines;
+
+import android.content.res.Resources;
+
+import com.android.dialer.helplines.utils.HelplineUtils;
+
+import org.lineageos.lib.phone.SensitivePhoneNumberInfo;
+
+public class HelplineItem {
+ private final SensitivePhoneNumberInfo mInfo;
+ private final String mName;
+
+ public HelplineItem(Resources res, SensitivePhoneNumberInfo info, String countryIso) {
+ mInfo = info;
+ mName = HelplineUtils.getName(res, info, countryIso);
+ }
+
+ public String getName() {
+ return mName;
+ }
+
+ public String get(String key) {
+ return mInfo.get(key);
+ }
+}
diff --git a/java/com/android/dialer/helplines/LoadHelplinesTask.java b/java/com/android/dialer/helplines/LoadHelplinesTask.java
new file mode 100644
index 000000000..7cc0a0152
--- /dev/null
+++ b/java/com/android/dialer/helplines/LoadHelplinesTask.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2019-2021 The LineageOS Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.dialer.helplines;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.os.AsyncTask;
+import android.support.annotation.NonNull;
+import android.telephony.SubscriptionInfo;
+import android.telephony.SubscriptionManager;
+import android.util.Log;
+
+import org.lineageos.lib.phone.SensitivePhoneNumberInfo;
+import org.lineageos.lib.phone.SensitivePhoneNumbers;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class LoadHelplinesTask extends AsyncTask<Void, Integer, List<HelplineItem>> {
+
+ @NonNull
+ private final Resources mResources;
+ @NonNull
+ private final SubscriptionManager mSubManager;
+ @NonNull
+ private final Callback mCallback;
+
+ LoadHelplinesTask(@NonNull Resources resources, @NonNull SubscriptionManager subManager,
+ @NonNull Callback callback) {
+ mResources = resources;
+ mSubManager = subManager;
+ mCallback = callback;
+ }
+
+ @Override
+ protected List<HelplineItem> doInBackground(Void... voids) {
+ List<HelplineItem> helplineList = new ArrayList<>();
+ /* when the network's and the user's country iso differ from each other,
+ * include the iso code in the name so one can be sure that the number is the correct one
+ * (think of accidential roaming close to the country border) */
+ boolean addCountryCode = false;
+
+ List<SubscriptionInfo> subList = getSubscriptionInfos();
+ if (subList != null) {
+ String localeCountryIso =
+ mResources.getConfiguration().locale.getCountry().toLowerCase();
+ List<String> alreadyProcessedMccs = new ArrayList<>();
+ for (SubscriptionInfo subInfo : subList) {
+ String subCountryIso = subInfo.getCountryIso();
+ if (!subCountryIso.equals(localeCountryIso)) {
+ addCountryCode = true;
+ }
+
+ String mcc = String.valueOf(subInfo.getMcc());
+ if (alreadyProcessedMccs.contains(mcc)) {
+ continue;
+ }
+ alreadyProcessedMccs.add(mcc);
+
+ SensitivePhoneNumbers spn = SensitivePhoneNumbers.getInstance();
+ ArrayList<SensitivePhoneNumberInfo> pns = spn.getSensitivePnInfosForMcc(mcc);
+ int numPns = pns.size();
+ for (int i = 0; i < numPns; i++) {
+ SensitivePhoneNumberInfo info = pns.get(i);
+ helplineList.add(new HelplineItem(mResources, info,
+ addCountryCode ? subCountryIso : ""));
+ publishProgress(Math.round(i * 100 / numPns / subList.size()));
+ }
+ }
+ }
+
+ Collections.sort(helplineList, (a, b) -> a.getName().compareTo(b.getName()));
+
+ return helplineList;
+ }
+
+ private List<SubscriptionInfo> getSubscriptionInfos() {
+ List<SubscriptionInfo> subList = mSubManager.getActiveSubscriptionInfoList();
+ if (subList == null) {
+ SubscriptionInfo info = mSubManager.getActiveSubscriptionInfo(
+ SubscriptionManager.getDefaultVoiceSubscriptionId());
+ if (info != null) {
+ subList = new ArrayList<>();
+ subList.add(info);
+ }
+ }
+ return subList;
+ }
+
+ @Override
+ protected void onProgressUpdate(Integer... values) {
+ if (values.length > 0) {
+ mCallback.onLoadListProgress(values[0]);
+ }
+ }
+
+ @Override
+ protected void onPostExecute(List<HelplineItem> list) {
+ mCallback.onLoadCompleted(list);
+ }
+
+ interface Callback {
+ void onLoadListProgress(int progress);
+
+ void onLoadCompleted(List<HelplineItem> result);
+ }
+}
diff --git a/java/com/android/dialer/helplines/res/drawable/ic_help.xml b/java/com/android/dialer/helplines/res/drawable/ic_help.xml
new file mode 100644
index 000000000..51a32eccf
--- /dev/null
+++ b/java/com/android/dialer/helplines/res/drawable/ic_help.xml
@@ -0,0 +1,26 @@
+<!--
+ Copyright (C) 2019-2021 The LineageOS Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0">
+ <path
+ android:fillColor="?android:attr/colorAccent"
+ android:pathData="M11,18h2v-2h-2v2zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,
+2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8zM12,6c-2.21,0 -4,
+1.79 -4,4h2c0,-1.1 0.9,-2 2,-2s2,0.9 2,2c0,2 -3,1.75 -3,5h2c0,-2.25 3,-2.5 3,-5 0,-2.21 -1.79,-4 -4,-4z"/>
+</vector>
diff --git a/java/com/android/dialer/helplines/res/drawable/ic_helpline_call.xml b/java/com/android/dialer/helplines/res/drawable/ic_helpline_call.xml
new file mode 100644
index 000000000..5d67f0359
--- /dev/null
+++ b/java/com/android/dialer/helplines/res/drawable/ic_helpline_call.xml
@@ -0,0 +1,25 @@
+<!--
+ Copyright (C) 2017 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0"
+ android:tint="?android:attr/textColorPrimary">
+ <path
+ android:fillColor="?android:attr/textColorPrimary"
+ android:pathData="M6.62,10.79c1.44,2.83 3.76,5.14 6.59,6.59l2.2,-2.2c0.27,-0.27 0.67,-0.36 1.02,-0.24 1.12,0.37 2.33,0.57 3.57,0.57 0.55,0 1,0.45 1,1V20c0,0.55 -0.45,1 -1,1 -9.39,0 -17,-7.61 -17,-17 0,-0.55 0.45,-1 1,-1h3.5c0.55,0 1,0.45 1,1 0,1.25 0.2,2.45 0.57,3.57 0.11,0.35 0.03,0.74 -0.25,1.02l-2.2,2.2z"/>
+</vector>
diff --git a/java/com/android/dialer/helplines/res/layout/activity_helplines.xml b/java/com/android/dialer/helplines/res/layout/activity_helplines.xml
new file mode 100644
index 000000000..c4cac0aab
--- /dev/null
+++ b/java/com/android/dialer/helplines/res/layout/activity_helplines.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2019-2021 The LineageOS Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <android.support.v7.widget.RecyclerView
+ android:id="@+id/helplines_list"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:visibility="gone" />
+
+ <LinearLayout
+ android:id="@+id/helplines_loading"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="center"
+ android:orientation="vertical">
+
+ <ProgressBar
+ android:id="@+id/helplines_progress_bar"
+ style="@android:style/Widget.DeviceDefault.ProgressBar.Horizontal"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:max="100"
+ android:paddingStart="32dp"
+ android:paddingEnd="32dp"
+ android:progress="0" />
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="16dp"
+ android:text="@string/helplines_loading"
+ android:textSize="16sp" />
+ </LinearLayout>
+
+ <LinearLayout
+ android:id="@+id/empty_view"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="center"
+ android:orientation="vertical"
+ android:visibility="gone">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="16dp"
+ android:gravity="center"
+ android:text="@string/helplines_empty"
+ android:textSize="16sp" />
+ </LinearLayout>
+</LinearLayout>
diff --git a/java/com/android/dialer/helplines/res/layout/dialog_helpline_details.xml b/java/com/android/dialer/helplines/res/layout/dialog_helpline_details.xml
new file mode 100644
index 000000000..4b283b2da
--- /dev/null
+++ b/java/com/android/dialer/helplines/res/layout/dialog_helpline_details.xml
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2019-2021 The LineageOS Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical"
+ android:paddingStart="24dp"
+ android:paddingTop="24dp"
+ android:paddingEnd="24dp"
+ android:paddingBottom="24dp">
+
+ <TextView
+ android:id="@+id/name_title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/helpline_name"
+ android:textSize="16dp"
+ android:textStyle="bold" />
+
+ <TextView
+ android:id="@+id/name"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:paddingBottom="8dp"
+ android:text="Name here"
+ android:textSize="16dp" />
+
+ <TextView
+ android:id="@+id/categories_title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/helpline_categories"
+ android:textSize="16dp"
+ android:textStyle="bold" />
+
+ <TextView
+ android:id="@+id/categories"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:paddingBottom="8dp"
+ android:text="Categories here"
+ android:textSize="16dp" />
+
+ <TextView
+ android:id="@+id/number_title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/helpline_number"
+ android:textSize="16dp"
+ android:textStyle="bold" />
+
+ <TextView
+ android:id="@+id/number"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:paddingBottom="8dp"
+ android:text="Number here"
+ android:textSize="16dp" />
+
+ <TextView
+ android:id="@+id/org_title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/helpline_org"
+ android:textSize="16dp"
+ android:textStyle="bold" />
+
+ <TextView
+ android:id="@+id/org"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:paddingBottom="8dp"
+ android:text="Org here"
+ android:textSize="16dp" />
+
+ <TextView
+ android:id="@+id/website_title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/helpline_website"
+ android:textSize="16dp"
+ android:textStyle="bold" />
+
+ <TextView
+ android:id="@+id/website"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Website here"
+ android:textSize="16dp" />
+</LinearLayout>
diff --git a/java/com/android/dialer/helplines/res/layout/item_helpline.xml b/java/com/android/dialer/helplines/res/layout/item_helpline.xml
new file mode 100644
index 000000000..5160105a4
--- /dev/null
+++ b/java/com/android/dialer/helplines/res/layout/item_helpline.xml
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2019-2021 The LineageOS Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:id="@+id/item"
+ android:background="?android:attr/selectableItemBackground"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:minHeight="48dp"
+ android:paddingTop="8dp"
+ android:paddingBottom="8dp">
+
+ <LinearLayout
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="16dp"
+ android:layout_weight="1"
+ android:orientation="vertical"
+ android:layout_gravity="center_vertical">
+
+ <TextView
+ android:id="@+id/item_helpline_title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="top|start"
+ tools:text="Title"
+ android:textColor="?android:attr/textColorPrimary"
+ android:textSize="@dimen/helpline_primary_text_size"/>
+
+ <TextView
+ android:id="@+id/item_helpline_categories"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ tools:text="Categories"
+ android:textColor="?android:attr/textColorSecondary"
+ android:visibility="gone"
+ tools:visibility="visible"
+ android:textSize="@dimen/helpline_secondary_text_size"/>
+
+ <TextView
+ android:id="@+id/item_helpline_languages"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ tools:text="Languages"
+ android:textColor="?android:attr/textColorSecondary"
+ android:visibility="gone"
+ tools:visibility="visible"
+ android:textSize="@dimen/helpline_secondary_text_size"/>
+ </LinearLayout>
+
+ <ImageView
+ android:id="@+id/item_helpline_call_icon"
+ android:layout_width="32dp"
+ android:layout_height="32dp"
+ android:layout_gravity="center|end"
+ android:layout_marginStart="16dp"
+ android:layout_marginEnd="16dp"
+ android:scaleType="center"
+ android:background="?android:attr/selectableItemBackgroundBorderless"
+ android:clickable="true"
+ android:focusable="true"
+ android:src="@drawable/ic_helpline_call"
+ android:visibility="visible"/>
+</LinearLayout>
diff --git a/java/com/android/dialer/helplines/res/menu/menu_helplines.xml b/java/com/android/dialer/helplines/res/menu/menu_helplines.xml
new file mode 100644
index 000000000..c4f99fc61
--- /dev/null
+++ b/java/com/android/dialer/helplines/res/menu/menu_helplines.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2019-2021 The LineageOS Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <item
+ android:id="@+id/menu_helpline_help"
+ android:icon="@drawable/ic_help"
+ android:showAsAction="always"
+ android:title="@string/helplines_help" />
+</menu>
diff --git a/java/com/android/dialer/helplines/res/values/dimens.xml b/java/com/android/dialer/helplines/res/values/dimens.xml
new file mode 100644
index 000000000..20fec7ede
--- /dev/null
+++ b/java/com/android/dialer/helplines/res/values/dimens.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2019-2021 The LineageOS Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources>
+ <dimen name="helpline_primary_text_size">16sp</dimen>
+ <dimen name="helpline_secondary_text_size">12sp</dimen>
+</resources>
diff --git a/java/com/android/dialer/helplines/res/values/helpline_categories.xml b/java/com/android/dialer/helplines/res/values/helpline_categories.xml
new file mode 100644
index 000000000..1e885f1f5
--- /dev/null
+++ b/java/com/android/dialer/helplines/res/values/helpline_categories.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2019-2021 The LineageOS Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources>
+ <string name="helpline_category_abuse">Abuse</string>
+ <string name="helpline_category_acohol">Alcohol</string>
+ <string name="helpline_category_addiction">Addiction</string>
+ <string name="helpline_category_adolescents">Adolescents</string>
+ <string name="helpline_category_adults">Adults</string>
+ <string name="helpline_category_aids">AIDS</string>
+ <string name="helpline_category_birth">Birth</string>
+ <string name="helpline_category_children">Children</string>
+ <string name="helpline_category_crime">Crime</string>
+ <string name="helpline_category_crime_victims">Crime Victims</string>
+ <string name="helpline_category_corruption">Corruption</string>
+ <string name="helpline_category_discrimination">Discrimination</string>
+ <string name="helpline_category_domestic_violence">Domestic Violence</string>
+ <string name="helpline_category_drugs">Drugs</string>
+ <string name="helpline_category_emotional_support">Emotional Support</string>
+ <string name="helpline_category_family">Family</string>
+ <string name="helpline_category_gambling">Gambling</string>
+ <string name="helpline_category_gender">Gender</string>
+ <string name="helpline_category_generic">Generic</string>
+ <string name="helpline_category_hiv">HIV</string>
+ <string name="helpline_category_human_rights">Human rights</string>
+ <string name="helpline_category_human_trafficking">Human Trafficking</string>
+ <string name="helpline_category_legal_aid">Legal Aid</string>
+ <string name="helpline_category_lgbtq">LGBTQ+</string>
+ <string name="helpline_category_men">Men</string>
+ <string name="helpline_category_mental_health">Mental Health</string>
+ <string name="helpline_category_missing_children">Missing children</string>
+ <string name="helpline_category_mothers">Mothers</string>
+ <string name="helpline_category_muslim">Muslim</string>
+ <string name="helpline_category_parents">Parents</string>
+ <string name="helpline_category_pregnancy">Pregnancy</string>
+ <string name="helpline_category_psychological">Psychological</string>
+ <string name="helpline_category_religion">Religion</string>
+ <string name="helpline_category_senior">Seniors</string>
+ <string name="helpline_category_sexual_abuse">Sexual Abuse</string>
+ <string name="helpline_category_sexual_assault">Sexual Assault</string>
+ <string name="helpline_category_sexual_rights">Sexual Rights</string>
+ <string name="helpline_category_sexuality">Sexuality</string>
+ <string name="helpline_category_soldiers">Soldiers</string>
+ <string name="helpline_category_suicide">Suicide Prevention</string>
+ <string name="helpline_category_trans">Transgender</string>
+ <string name="helpline_category_veterans">Veterans</string>
+ <string name="helpline_category_violence">Violence</string>
+ <string name="helpline_category_war">War</string>
+ <string name="helpline_category_women">Women</string>
+ <string name="helpline_category_youth">Youth</string>
+</resources>
diff --git a/java/com/android/dialer/helplines/res/values/helpline_names.xml b/java/com/android/dialer/helplines/res/values/helpline_names.xml
new file mode 100644
index 000000000..5ca02acdd
--- /dev/null
+++ b/java/com/android/dialer/helplines/res/values/helpline_names.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2019-2021 The LineageOS Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources>
+
+</resources>
diff --git a/java/com/android/dialer/helplines/res/values/strings.xml b/java/com/android/dialer/helplines/res/values/strings.xml
new file mode 100644
index 000000000..232ac46a8
--- /dev/null
+++ b/java/com/android/dialer/helplines/res/values/strings.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2019-2021 The LineageOS Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="helplines_name">Helplines</string>
+ <string name="helplines_loading">Loading\u2026</string>
+ <string name="helplines_empty">No helplines found.\nInsert a sim card and try again</string>
+ <string name="helplines_help">Help</string>
+ <string name="helplines_help_title">These are safe to call</string>
+ <string name="helplines_help_message">None of these numbers appear in your call history.\nYou can click any item for more information</string>
+
+ <string name="helplines_help_more_message">The list of helplines is filled with information that is updated manually by contributors. If you encounter any missing or wrong information, please feel free to contact us at www.lineageos.org</string>
+
+ <string name="helpline_button_more">More</string>
+
+ <string name="unknown_helpline_name">Unknown Organisation</string>
+
+ <string name="helpline_name">Name</string>
+ <string name="helpline_org">Organization</string>
+ <string name="helpline_categories">Categories</string>
+ <string name="helpline_number">Number</string>
+ <string name="helpline_website">Website</string>
+ <string name="helpline_browser_history_title">Attention</string>
+ <string name="helpline_browser_history_message">Don\'t forget to clear the browser history</string>
+
+ <!-- Format for displaying a helpline name with the country - Example will resolve to "Emotional Support Hotline (US)" -->
+ <string name="helpline_name_format_country"><xliff:g id="helpline_name" example="Emotional Support Helpline">%1$s</xliff:g> (<xliff:g id="helpline_county" example="US">%2$s</xliff:g>)</string>
+
+ <string name="helpline_language_cree">Cree</string>
+ <string name="helpline_language_english">English</string>
+ <string name="helpline_language_french">French</string>
+ <string name="helpline_language_german">German</string>
+ <string name="helpline_language_inuktitut">Inuktitut</string>
+ <string name="helpline_language_ojibway">Ojibway</string>
+ <string name="helpline_language_turkish">Turkish</string>
+</resources>
diff --git a/java/com/android/dialer/helplines/res/values/styles.xml b/java/com/android/dialer/helplines/res/values/styles.xml
new file mode 100755
index 000000000..4df1e1c1d
--- /dev/null
+++ b/java/com/android/dialer/helplines/res/values/styles.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2019-2021 The LineageOS Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources>
+ <style name="BaseTheme" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar">
+ <item name="android:windowBackground">@android:color/transparent</item>
+ <item name="android:colorBackgroundCacheHint">@null</item>
+ <item name="android:windowShowWallpaper">true</item>
+ <item name="android:windowNoTitle">true</item>
+ <item name="android:colorEdgeEffect">#FF757575</item>
+ </style>
+
+ <style name="BaseTheme.Dark" parent="@style/BaseTheme">
+ <item name="android:textColorPrimary">#FFFFFFFF</item>
+ <item name="android:textColorSecondary">#FFFFFFFF</item>
+ <item name="android:textColorTertiary">#CCFFFFFF</item>
+ <item name="android:textColorHint">#A0FFFFFF</item>
+ <item name="android:colorControlHighlight">#A0FFFFFF</item>
+ <item name="android:colorPrimary">#FF212121</item>
+ </style>
+
+ <!-- A derivative project can extend these themes to customize the application theme without
+ affecting the base theme -->
+ <style name="HelplineTheme" parent="@style/BaseTheme" />
+ <style name="HelplineTheme.Dark" parent="@style/BaseTheme.Dark" />
+</resources>
diff --git a/java/com/android/dialer/helplines/utils/HelplineUtils.java b/java/com/android/dialer/helplines/utils/HelplineUtils.java
new file mode 100644
index 000000000..4ff20b93c
--- /dev/null
+++ b/java/com/android/dialer/helplines/utils/HelplineUtils.java
@@ -0,0 +1,91 @@
+/**
+ * Copyright (C) 2019-2021 The LineageOS Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.dialer.helplines.utils;
+
+import android.content.res.Resources;
+import android.text.TextUtils;
+
+import com.android.dialer.R;
+import com.android.dialer.helplines.HelplineItem;
+import org.lineageos.lib.phone.SensitivePhoneNumberInfo;
+
+import java.util.ArrayList;
+
+public class HelplineUtils {
+
+ private static final String TAG = HelplineUtils.class.getSimpleName();
+ private static final String NAME_STR_FORMAT = "helpline_name_%s";
+ private static final String CATEGORY_STR_FORMAT = "helpline_category_%s";
+ private static final String LANGUAGE_STR_FORMAT = "helpline_language_%s";
+
+ /* Get the name of the helpline, fall back to the number if not given */
+ public static String getName(Resources res, SensitivePhoneNumberInfo info, String countryIso) {
+ if (info != null) {
+ String name = info.get("name");
+ String displayName = !TextUtils.isEmpty(name)
+ ? getDisplayString(res, name, NAME_STR_FORMAT)
+ : info.get("number");
+ if (!TextUtils.isEmpty(countryIso)) {
+ return res.getString(R.string.helpline_name_format_country, displayName,
+ countryIso);
+ } else {
+ return displayName;
+ }
+ }
+
+ return "";
+ }
+
+ /* Split the given categories and translate them, fall back to "generic" if not given */
+ public static String getCategories(Resources res, HelplineItem item) {
+ if (item != null) {
+ String str = getDisplayString(res, item.get("categories"), CATEGORY_STR_FORMAT);
+ if (!TextUtils.isEmpty(str)) {
+ return str;
+ }
+ }
+
+ return res.getString(R.string.helpline_category_generic);
+ }
+
+ /* Split and translate the given languages, return empty string if not given */
+ public static String getLanguages(Resources res, HelplineItem item) {
+ if (item != null) {
+ return getDisplayString(res, item.get("languages"), LANGUAGE_STR_FORMAT);
+ }
+
+ return "";
+ }
+
+ /* Split the content at the pipe symbol and get a resource named according to each item
+ matching a pattern
+ */
+ private static String getDisplayString(Resources res, String content, String pattern) {
+ if (content != null && content.length() > 0) {
+ String[] listItems = TextUtils.split(content, "\\|");
+ ArrayList<String> list = new ArrayList<>();
+ for (String item : listItems) {
+ String l = ResourceUtils.getLocalizedString(res, item, pattern);
+ list.add(l);
+ }
+ if (list.size() > 0) {
+ return TextUtils.join(", ", list);
+ }
+ return content;
+ }
+ return "";
+ }
+}
diff --git a/java/com/android/dialer/helplines/utils/ResourceUtils.java b/java/com/android/dialer/helplines/utils/ResourceUtils.java
new file mode 100644
index 000000000..7c6d403f6
--- /dev/null
+++ b/java/com/android/dialer/helplines/utils/ResourceUtils.java
@@ -0,0 +1,54 @@
+/**
+ * Copyright (C) 2016 The CyanogenMod project
+ * Copyright (C) 2019 The LineageOS Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.dialer.helplines.utils;
+
+import android.content.res.Resources;
+import android.util.Log;
+
+public class ResourceUtils {
+
+ private static final String TAG = ResourceUtils.class.getSimpleName();
+ private static final boolean DEBUG = false;
+
+ public static String getLocalizedString(final Resources res,
+ final String stringName,
+ final String stringFormat) {
+ String name = stringName.toLowerCase();
+ final String[] nonTokens = { "'", ",", "- ", "-", "(", ")" };
+ for (String token : nonTokens) {
+ name = name.replace(token, "");
+ }
+ final String[] underscoreTokens = { " ", "/" };
+ for (String token : underscoreTokens) {
+ name = name.replace(token, "_");
+ }
+ final String nameRes = String.format(stringFormat, name);
+ return getStringForResourceName(res, nameRes, stringName);
+ }
+
+ public static String getStringForResourceName(final Resources res,
+ final String resourceName,
+ final String defaultValue) {
+ final int resId = res.getIdentifier(resourceName, "string", "com.android.dialer");
+ if (resId <= 0) {
+ if (DEBUG) Log.d(TAG, "No resource found for " + resourceName);
+ return defaultValue;
+ } else {
+ return res.getString(resId);
+ }
+ }
+}
diff --git a/java/com/android/dialer/main/impl/MainSearchController.java b/java/com/android/dialer/main/impl/MainSearchController.java
index 364f5bc76..515f11bbe 100644
--- a/java/com/android/dialer/main/impl/MainSearchController.java
+++ b/java/com/android/dialer/main/impl/MainSearchController.java
@@ -41,6 +41,7 @@ import com.android.dialer.constants.ActivityRequestCodes;
import com.android.dialer.dialpadview.DialpadFragment;
import com.android.dialer.dialpadview.DialpadFragment.DialpadListener;
import com.android.dialer.dialpadview.DialpadFragment.OnDialpadQueryChangedListener;
+import com.android.dialer.helplines.HelplineActivity;
import com.android.dialer.logging.DialerImpression;
import com.android.dialer.logging.Logger;
import com.android.dialer.logging.ScreenEvent;
@@ -479,6 +480,8 @@ public class MainSearchController implements SearchBarListener {
} else if (menuItem.getItemId() == R.id.menu_call_history) {
final Intent intent = new Intent(activity, CallLogActivity.class);
activity.startActivity(intent);
+ } else if (menuItem.getItemId() == R.id.menu_helplines) {
+ activity.startActivity(new Intent(activity, HelplineActivity.class));
}
return false;
}
diff --git a/java/com/android/dialer/main/impl/toolbar/res/menu/main_menu.xml b/java/com/android/dialer/main/impl/toolbar/res/menu/main_menu.xml
index 0e354cece..c75a17d01 100644
--- a/java/com/android/dialer/main/impl/toolbar/res/menu/main_menu.xml
+++ b/java/com/android/dialer/main/impl/toolbar/res/menu/main_menu.xml
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2018 The Android Open Source Project
+ ~ Copyright (C) 2021 The LineageOS Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
@@ -29,6 +30,10 @@
android:visible="false"/>
<item
+ android:id="@+id/menu_helplines"
+ android:title="@string/action_menu_helplines"/>
+
+ <item
android:id="@+id/settings"
android:title="@string/settings"
app:showAsAction="collapseActionView"/>