blob: b916247ad2cf8a73f238e82d98c940c53b56a45d [file] [log] [blame]
Eric Erfanianccca3152017-02-22 16:32:36 -08001/**
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
15 */
16
17package com.android.voicemailomtp;
18
19import android.app.ActionBar;
20import android.content.Context;
21import android.content.Intent;
22import android.content.res.Resources;
23import android.text.TextUtils;
24
25/**
26 * Helper for manipulating intents or components with subscription-related information.
27 *
28 * In settings, subscription ids and labels are passed along to indicate that settings
29 * are being changed for particular subscriptions. This helper provides functions for
30 * helping extract this info and perform common operations using this info.
31 */
32public class SubscriptionInfoHelper {
33 public static final int NO_SUB_ID = -1;
34
35 // Extra on intent containing the id of a subscription.
36 public static final String SUB_ID_EXTRA =
37 "com.android.voicemailomtp.settings.SubscriptionInfoHelper.SubscriptionId";
38 // Extra on intent containing the label of a subscription.
39 private static final String SUB_LABEL_EXTRA =
40 "com.android.voicemailomtp.settings.SubscriptionInfoHelper.SubscriptionLabel";
41
42 private static Context mContext;
43
44 private static int mSubId = NO_SUB_ID;
45 private static String mSubLabel;
46
47 /**
48 * Instantiates the helper, by extracting the subscription id and label from the intent.
49 */
50 public SubscriptionInfoHelper(Context context, Intent intent) {
51 mContext = context;
52 mSubId = intent.getIntExtra(SUB_ID_EXTRA, NO_SUB_ID);
53 mSubLabel = intent.getStringExtra(SUB_LABEL_EXTRA);
54 }
55
56 /**
57 * Sets the action bar title to the string specified by the given resource id, formatting
58 * it with the subscription label. This assumes the resource string is formattable with a
59 * string-type specifier.
60 *
61 * If the subscription label does not exists, leave the existing title.
62 */
63 public void setActionBarTitle(ActionBar actionBar, Resources res, int resId) {
64 if (actionBar == null || TextUtils.isEmpty(mSubLabel)) {
65 return;
66 }
67
68 String title = String.format(res.getString(resId), mSubLabel);
69 actionBar.setTitle(title);
70 }
71
72 public int getSubId() {
73 return mSubId;
74 }
75}