Show tolled support number when click travel abroad.

Bug: 29105266
Change-Id: I3020039bafe26e8a494075ad2f192dba07ab6dd0
This commit is contained in:
Fan Zhang
2016-06-24 11:33:35 -07:00
parent dbb8cab438
commit 3737fabda4
6 changed files with 186 additions and 3 deletions

View File

@@ -40,6 +40,7 @@ import com.android.settings.R;
import com.android.settings.overlay.SupportFeatureProvider;
import com.android.settings.support.SupportDisclaimerDialogFragment;
import com.android.settings.support.SupportPhone;
import com.android.settings.support.SupportPhoneDialogFragment;
import java.util.ArrayList;
import java.util.List;
@@ -367,15 +368,23 @@ public final class SupportItemAdapter extends RecyclerView.Adapter<SupportItemAd
}
} else {
switch (v.getId()) {
case android.R.id.text1:
case android.R.id.text1: {
final SupportPhone phone = mSupportFeatureProvider
.getSupportPhones(mSelectedCountry, true /* isTollFree */);
if (phone != null) {
mActivity.startActivity(phone.getDialIntent());
}
break;
case android.R.id.text2:
}
case android.R.id.text2: {
final SupportPhone phone = mSupportFeatureProvider
.getSupportPhones(mSelectedCountry, false /* isTollFree */);
final SupportPhoneDialogFragment fragment =
SupportPhoneDialogFragment.newInstance(phone);
fragment.show(mActivity.getFragmentManager(),
SupportPhoneDialogFragment.TAG);
break;
}
}
}
}

View File

@@ -18,6 +18,8 @@ package com.android.settings.support;
import android.content.Intent;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import java.text.ParseException;
@@ -25,7 +27,7 @@ import java.text.ParseException;
/**
* Data model for a support phone number.
*/
public final class SupportPhone {
public final class SupportPhone implements Parcelable {
public final String language;
public final String number;
@@ -42,6 +44,12 @@ public final class SupportPhone {
number = tokens[2];
}
protected SupportPhone(Parcel in) {
language = in.readString();
number = in.readString();
isTollFree = in.readInt() != 0;
}
public Intent getDialIntent() {
return new Intent(Intent.ACTION_DIAL)
.setData(new Uri.Builder()
@@ -49,4 +57,28 @@ public final class SupportPhone {
.appendPath(number)
.build());
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(language);
dest.writeString(number);
dest.writeInt(isTollFree ? 1 : 0);
}
public static final Creator<SupportPhone> CREATOR = new Creator<SupportPhone>() {
@Override
public SupportPhone createFromParcel(Parcel in) {
return new SupportPhone(in);
}
@Override
public SupportPhone[] newArray(int size) {
return new SupportPhone[size];
}
};
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright (C) 2016 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.
*/
package com.android.settings.support;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import com.android.settings.R;
import java.util.Locale;
/**
* A dialog fragment that displays support phone numbers.
*/
public final class SupportPhoneDialogFragment extends DialogFragment implements
View.OnClickListener {
public static final String TAG = "SupportPhoneDialog";
private static final String EXTRA_PHONE = "extra_phone";
public static SupportPhoneDialogFragment newInstance(SupportPhone phone) {
final SupportPhoneDialogFragment fragment = new SupportPhoneDialogFragment();
final Bundle bundle = new Bundle(2);
bundle.putParcelable(EXTRA_PHONE, phone);
fragment.setArguments(bundle);
return fragment;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final SupportPhone phone = getArguments().getParcelable(EXTRA_PHONE);
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
.setTitle(R.string.support_international_phone_title);
final View content = LayoutInflater.from(builder.getContext())
.inflate(R.layout.support_phone_dialog_content, null);
final TextView phoneView = (TextView) content.findViewById(R.id.phone_number);
final String formattedPhoneNumber = getContext().getString(
R.string.support_phone_international_format,
new Locale(phone.language).getDisplayLanguage(), phone.number);
phoneView.setText(formattedPhoneNumber);
phoneView.setOnClickListener(this);
return builder
.setView(content)
.create();
}
@Override
public void onClick(View v) {
final SupportPhone phone = getArguments().getParcelable(EXTRA_PHONE);
getActivity().startActivity(phone.getDialIntent());
dismiss();
}
}