diff options
author | Raj Yengisetty <raj@cyngn.com> | 2016-02-12 12:43:43 -0800 |
---|---|---|
committer | Richard MacGregor <rmacgregor@cyngn.com> | 2016-04-08 10:42:50 -0700 |
commit | a1aefab78ec4c7de7f69b5c3a6362f6ebe9d79f9 (patch) | |
tree | 207993e6e02ccf0b2e2cbc37072db551ab0ecd2c /src-ambient | |
parent | 95562ec70e8c61a010a77279540a1149844d11ce (diff) | |
download | packages_apps_PhoneCommon-a1aefab78ec4c7de7f69b5c3a6362f6ebe9d79f9.tar.gz packages_apps_PhoneCommon-a1aefab78ec4c7de7f69b5c3a6362f6ebe9d79f9.tar.bz2 packages_apps_PhoneCommon-a1aefab78ec4c7de7f69b5c3a6362f6ebe9d79f9.zip |
InCall: move CreditBarHelper to src-ambient
Change-Id: I41cb619fc6e9fb759c3b4e388b4606e145d3c39c
Diffstat (limited to 'src-ambient')
-rw-r--r-- | src-ambient/incall/CreditBarHelper.java | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src-ambient/incall/CreditBarHelper.java b/src-ambient/incall/CreditBarHelper.java new file mode 100644 index 0000000..62116c1 --- /dev/null +++ b/src-ambient/incall/CreditBarHelper.java @@ -0,0 +1,93 @@ +package com.android.phone.common.incall; + +import android.app.PendingIntent; +import android.content.res.Resources; +import android.text.TextUtils; +import android.util.Log; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import com.android.phone.common.R; +import com.android.phone.common.incall.CallMethodInfo; + +/** + * Helper method used to handle incall credit bars + * + * The credit bar's origin code comes from google. We've added a second credit bar in dialer that + * uses these same helper method. + */ +public class CreditBarHelper { + + private static final String TAG = CreditBarHelper.class.getSimpleName(); + + public interface CreditBarVisibilityListener { + public void creditsBarVisibilityChanged(int visibility); + } + + public static void clearCallRateInformation(ViewGroup v, CreditBarVisibilityListener cpvl) { + setCallRateInformation(v, null, null, null, cpvl); + } + + public static void setCallRateInformation(ViewGroup creditsBar, String countryName, + String displayRate, final PendingIntent p, + CreditBarVisibilityListener cpvl) { + if (TextUtils.isEmpty(countryName) && TextUtils.isEmpty(displayRate) && + p == null) { + creditsBar.setVisibility(View.GONE); + cpvl.creditsBarVisibilityChanged(View.GONE); + return; + } + creditsBar.setVisibility(View.VISIBLE); + cpvl.creditsBarVisibilityChanged(View.VISIBLE); + TextView ildCountry = (TextView) creditsBar.findViewById(R.id.ild_country); + TextView ildRate = (TextView) creditsBar.findViewById(R.id.ild_rate); + + ildCountry.setText(countryName); + ildRate.setText(displayRate); + ildRate.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + try { + if (p != null) { + p.send(); + } else { + Log.wtf(TAG, "The intent we attempted to fire was null"); + } + } catch (PendingIntent.CanceledException e) { + e.printStackTrace(); + } + } + }); + } + + public static void callMethodCredits(ViewGroup v, CallMethodInfo cmi, Resources r, + CreditBarVisibilityListener cpvl) { + String creditText = cmi.getCreditsDescriptionText(r); + String buttonText = null; + PendingIntent button; + + boolean warnIfLow = false; + if (TextUtils.isEmpty(creditText)) { + clearCallRateInformation(v, cpvl); + return; + } else { + if (cmi.mIsAuthenticated) { + button = cmi.mManageCreditIntent; + if (cmi.usesSubscriptions()) { + buttonText = cmi.mSubscriptionButtonText; + } else { + if (cmi.getCurrencyAmount() <= cmi.mCreditWarn) { + warnIfLow = true; + } + buttonText = cmi.mCreditButtonText; + } + } else { + buttonText = r.getString(R.string.sign_in_credit_banner_text); + creditText = ""; + button = cmi.mLoginIntent; + } + } + setCallRateInformation(v, creditText, buttonText, button, cpvl); + } +} |