Java Code Examples for android.content.Context#getString()

The following examples show how to use android.content.Context#getString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlaybackControlsRow.java    From adt-leanback-support with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor
 * @param context Context used for loading resources.
 * @param highlightColor Color for the highlighted icon state.
 */
public ClosedCaptioningAction(Context context, int highlightColor) {
    super(R.id.lb_control_high_quality);
    BitmapDrawable uncoloredDrawable = (BitmapDrawable) getStyledDrawable(context,
            R.styleable.lbPlaybackControlsActionIcons_closed_captioning);
    Drawable[] drawables = new Drawable[2];
    drawables[OFF] = uncoloredDrawable;
    drawables[ON] = new BitmapDrawable(context.getResources(),
            createBitmap(uncoloredDrawable.getBitmap(), highlightColor));
    setDrawables(drawables);

    String[] labels = new String[drawables.length];
    labels[OFF] = context.getString(R.string.lb_playback_controls_closed_captioning_enable);
    labels[ON] = context.getString(R.string.lb_playback_controls_closed_captioning_disable);
    setLabels(labels);
}
 
Example 2
Source File: SupportEmailUtil.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private static @NonNull String buildSystemInfo(@NonNull Context context, @NonNull String subject) {
  return "--- " + context.getString(R.string.HelpFragment__support_info) + " ---" +
         "\n" +
         context.getString(R.string.SupportEmailUtil_subject) + " " + subject +
         "\n" +
         context.getString(R.string.SupportEmailUtil_device_info) + " " + getDeviceInfo() +
         "\n" +
         context.getString(R.string.SupportEmailUtil_android_version) + " " + getAndroidVersion() +
         "\n" +
         context.getString(R.string.SupportEmailUtil_signal_version) + " " + getSignalVersion() +
         "\n" +
         context.getString(R.string.SupportEmailUtil_signal_package) + " " + getSignalPackage(context) +
         "\n" +
         context.getString(R.string.SupportEmailUtil_registration_lock) + " " + getRegistrationLockEnabled(context) +
         "\n" +
         context.getString(R.string.SupportEmailUtil_locale) + " " + Locale.getDefault().toString();
}
 
Example 3
Source File: ConnectFailUtils.java    From MiPushFramework with GNU General Public License v3.0 6 votes vote down vote up
public static CharSequence getSummary(Context context,
                                      @OnConnectStatusChangedListener.FailReason int reason,
                                      int serviceVersionCode) {
    switch (reason) {
        case FAIL_REASON_SECURITY_EXCEPTION:
            return Utils.toHtml(context.getString(R.string.connect_fail_test_se, MANAGER_APK_URL));
        case FAIL_REASON_UNKNOWN:
            return getString(R.string.connect_fail_text_unknown, context,
                    getString(top.trumeet.common.R.string.push_service_name, context));
        case FAIL_REASON_NOT_INSTALLED:
            String original = context.getString(R.string.connect_fail_text_not_installed,
                    SERVICE_APK_URL);
            return Utils.toHtml(original);
        case FAIL_REASON_LOW_VERSION:
            return getString(R.string.connect_fail_text_low_version, context,
                    String.valueOf(serviceVersionCode),
                    SERVICE_APK_URL);
        case FAIL_REASON_MIUI:
            return getString(R.string.connect_fail_text_is_miui, context);
        default:
            return "";
    }
}
 
Example 4
Source File: TipsDialog.java    From VSigner with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 默认title
 * @param context
 * @param message
 * @param buttonText
 * @param negetiveText
 * @param isCancel
 */
public TipsDialog(Context context,String message,String buttonText,String negetiveText,boolean isCancel) {
	super(context);
	super.setMessage(message);
	super.setNamePositiveButton(buttonText);
	this.hasNegative=false;
	super.setNameNegativeButton(negetiveText);
	this.hasTitle = true;
	super.setTitle(context.getString(R.string.default_tips_title));
	super.setCancel(isCancel);
}
 
Example 5
Source File: Filepath.java    From Mizuu with Apache License 2.0 5 votes vote down vote up
public String getTypeAsString(Context context) {
    if (getType() == FileSource.SMB) {
        return context.getString(R.string.contentLocationSMB_Alternative);
    } else if (getType() == FileSource.UPNP) {
        return context.getString(R.string.contentLocationUPnP_Alternative);
    } else {
        return context.getString(R.string.contentLocationDevice_Alternative);
    }
}
 
Example 6
Source File: DateTool.java    From intra42 with Apache License 2.0 5 votes vote down vote up
public static String getTodayTomorrow(Context context, java.util.Date date, boolean hyphen) {
    String str = "";
    if (DateTool.isToday(date)) {
        str = context.getString(R.string.today);
        if (hyphen)
            str += " - ";
    } else if (DateTool.isTomorrow(date)) {
        str = context.getString(R.string.tomorrow);
        if (hyphen)
            str += " - ";
    }
    return str;
}
 
Example 7
Source File: DialogTest.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
public static void showHelpDialog(Context context, boolean verify)
{
    String actionHelpText = context.getString(R.string.configAction_help);
    openActionBarOverflowOrOptionsMenu(InstrumentationRegistry.getTargetContext());
    onView(withText(actionHelpText)).perform(click());
    if (verify) {
        verifyHelpDialog();
    }
}
 
Example 8
Source File: LogItem.java    From Cybernet-VPN with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint({"StringFormatMatches", "StringFormatInvalid"})
private String getMobileInfoString(Context c) {
    c.getPackageManager();
    String apksign = "error getting package signature";
    String version = "error getting version";
    try {
        @SuppressLint("PackageManagerGetSignatures") Signature raw = c.getPackageManager().getPackageInfo(c.getPackageName(), PackageManager.GET_SIGNATURES).signatures[0];
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        X509Certificate cert = (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(raw.toByteArray()));
        MessageDigest md = MessageDigest.getInstance("SHA-1");
        byte[] der = cert.getEncoded();
        md.update(der);
        byte[] digest = md.digest();
        if (Arrays.equals(digest, VpnStatus.officalkey)) apksign = c.getString(R.string.official_build);
        else if (Arrays.equals(digest, VpnStatus.officaldebugkey)) apksign = c.getString(R.string.debug_build);
        else if (Arrays.equals(digest, VpnStatus.amazonkey)) apksign = "amazon version";
        else if (Arrays.equals(digest, VpnStatus.fdroidkey)) apksign = "F-Droid built and signed version";
        else apksign = c.getString(R.string.built_by, cert.getSubjectX500Principal().getName());
        PackageInfo packageinfo = c.getPackageManager().getPackageInfo(c.getPackageName(), 0);
        version = packageinfo.versionName;
    } catch (PackageManager.NameNotFoundException | CertificateException |
            NoSuchAlgorithmException ignored) {
    }
    Object[] argsext = Arrays.copyOf(mArgs, mArgs.length);
    argsext[argsext.length - 1] = apksign;
    argsext[argsext.length - 2] = version;
    return c.getString(R.string.mobile_info, argsext);
}
 
Example 9
Source File: Clog.java    From mobile-sdk-android with Apache License 2.0 5 votes vote down vote up
public static String getString(int id, boolean b) {
    Context error_context = clog_context.get();

    if (error_context == null)
        return "";
    return error_context.getString(id, b);
}
 
Example 10
Source File: VpnStatus.java    From Cake-VPN with GNU General Public License v2.0 5 votes vote down vote up
public static String getLastCleanLogMessage(Context c) {
        String message = mLaststatemsg;
        switch (mLastLevel) {
            case LEVEL_CONNECTED:
                String[] parts = mLaststatemsg.split(",");
                /*
                   (a) the integer unix date/time,
                   (b) the state name,
                   0 (c) optional descriptive string (used mostly on RECONNECTING
                    and EXITING to show the reason for the disconnect),
                    1 (d) optional TUN/TAP local IPv4 address
                   2 (e) optional address of remote server,
                   3 (f) optional port of remote server,
                   4 (g) optional local address,
                   5 (h) optional local port, and
                   6 (i) optional TUN/TAP local IPv6 address.
*/
                // Return only the assigned IP addresses in the UI
                if (parts.length >= 7) message = String.format(Locale.US, "%s %s", parts[1], parts[6]);
                break;
        }
        while (message.endsWith(",")) message = message.substring(0, message.length() - 1);
        String status = mLaststate;
        if (status.equals("NOPROCESS")) return message;
        if (mLastStateresid == R.string.state_waitconnectretry) {
            return c.getString(R.string.state_waitconnectretry, mLaststatemsg);
        }
        String prefix = c.getString(mLastStateresid);
        if (mLastStateresid == R.string.unknown_state) message = status + message;
        if (message.length() > 0) prefix += ": ";
        return prefix + message;
    }
 
Example 11
Source File: ActionBroadcastReceiver.java    From AndroidProjects with MIT License 5 votes vote down vote up
private String getToastText(Context context, int actionId, String url) {
    switch (actionId) {
        case ACTION_ACTION_BUTTON:
            return context.getString(R.string.action_button_toast_text, url);
        case ACTION_MENU_ITEM:
            return context.getString(R.string.menu_item_toast_text, url);
        case ACTION_TOOLBAR:
            return context.getString(R.string.toolbar_toast_text, url);
        default:
            return context.getString(R.string.unknown_toast_text, url);
    }
}
 
Example 12
Source File: PullToRefreshRecyclerViewUtils.java    From Collection-Android with MIT License 5 votes vote down vote up
/**
 * 时间转换
 * @param time
 * @return
 */
public static String getTimeConvert(Context context,long time) {
	//获取time距离当前的秒数
	int ct = (int)((System.currentTimeMillis() - time)/1000);

	if(ct <=15) {
		return context.getString(R.string.collection_refresh_just);
	}

	if(ct >15 && ct < 60) {
		return ct+context.getString(R.string.collection_refresh_seconds_ago);
	}

	if(ct >= 60 && ct < 3600) {
		return Math.max(ct / 60,1) +context.getString(R.string.collection_refresh_minutes_ago);
	}
	if(ct >= 3600 && ct < 86400)
		return ct / 3600 + context.getString(R.string.collection_refresh_hours_ago);
	if(ct >= 86400 && ct < 2592000){ //86400 * 30
		int day = ct / 86400 ;
		return day + context.getString(R.string.collection_refresh_days_ago);
	}
	if(ct >= 2592000 && ct < 31104000) { //86400 * 30
		return ct / 2592000 + context.getString(R.string.collection_refresh_months_ago);
	}
	return ct / 31104000 + context.getString(R.string.collection_refresh_years_ago);
}
 
Example 13
Source File: PayeeByPeriodReport.java    From financisto with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String getNoFilterMessage(Context context) {
    return context.getString(R.string.report_no_payee);
}
 
Example 14
Source File: UIHelper.java    From Pix-Art-Messenger with GNU General Public License v3.0 4 votes vote down vote up
public static Pair<CharSequence, Boolean> getMessagePreview(final Context context, final Message message, @ColorInt int textColor) {
      final Transferable d = message.getTransferable();
      if (d != null) {
          switch (d.getStatus()) {
              case Transferable.STATUS_WAITING:
                  return new Pair<>(context.getString(R.string.waiting_for_transfer), true);
              case Transferable.STATUS_CHECKING:
                  return new Pair<>(context.getString(R.string.checking_x,
                          getFileDescriptionString(context, message)), true);
              case Transferable.STATUS_DOWNLOADING:
                  return new Pair<>(context.getString(R.string.receiving_file,
                          getFileDescriptionString(context, message)), true);
              case Transferable.STATUS_OFFER:
              case Transferable.STATUS_OFFER_CHECK_FILESIZE:
                  return new Pair<>(context.getString(R.string.x_file_offered_for_download,
                          getFileDescriptionString(context, message)), true);
              case Transferable.STATUS_FAILED:
                  return new Pair<>(context.getString(R.string.file_transmission_failed), true);
              case Transferable.STATUS_CANCELLED:
                  return new Pair<>(context.getString(R.string.file_transmission_cancelled), true);
              case Transferable.STATUS_UPLOADING:
                  if (message.getStatus() == Message.STATUS_OFFERED) {
                      return new Pair<>(context.getString(R.string.offering_x_file,
                              getFileDescriptionString(context, message)), true);
                  } else {
                      return new Pair<>(context.getString(R.string.sending_x_file,
                              getFileDescriptionString(context, message)), true);
                  }
              default:
                  return new Pair<>("", false);
          }
      } else if (message.isFileOrImage() && message.isFileDeleted()) {
          return new Pair<>(context.getString(R.string.file_deleted), true);
      } else if (message.getEncryption() == Message.ENCRYPTION_PGP) {
          return new Pair<>(context.getString(R.string.pgp_message), true);
      } else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
          return new Pair<>(context.getString(R.string.decryption_failed), true);
      } else if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL_NOT_FOR_THIS_DEVICE) {
          return new Pair<>(context.getString(R.string.not_encrypted_for_this_device), true);
      } else if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL_FAILED) {
          return new Pair<>(context.getString(R.string.omemo_decryption_failed), true);
      } else if (message.isFileOrImage()) {
          return new Pair<>(getFileDescriptionString(context, message), true);
} else if (message.getType() == Message.TYPE_RTP_SESSION) {
	RtpSessionStatus rtpSessionStatus = RtpSessionStatus.of(message.getBody());
	final boolean received = message.getStatus() == Message.STATUS_RECEIVED;
	if (!rtpSessionStatus.successful && received) {
		return new Pair<>(context.getString(R.string.missed_call),true);
	} else {
		return new Pair<>(context.getString(received ? R.string.incoming_call : R.string.outgoing_call), true);
	}
      } else {
          final String body = MessageUtils.filterLtrRtl(message.getBody());
          if (message.getBody().equals(DELETED_MESSAGE_BODY) || message.getBody().equals(DELETED_MESSAGE_BODY_OLD)) {
              return new Pair<>(context.getString(R.string.message_deleted), false);
          } else if (body.startsWith(Message.ME_COMMAND)) {
              return new Pair<>(body.replaceAll("^" + Message.ME_COMMAND, UIHelper.getMessageDisplayName(message)), false);
          } else if (message.isGeoUri()) {
              return new Pair<>(context.getString(R.string.location), true);
          } else if (message.isXmppUri()) {
              return new Pair<>(context.getString(R.string.contact), true);
          } else if (message.treatAsDownloadable() || MessageUtils.unInitiatedButKnownSize(message)) {
              return new Pair<>(context.getString(R.string.x_file_offered_for_download,
                      getFileDescriptionString(context, message)), true);
          } else {
              SpannableStringBuilder styledBody = new SpannableStringBuilder(MyLinkify.replaceYoutube(context, body));
              if (textColor != 0) {
                  StylingHelper.format(styledBody, 0, styledBody.length() - 1, textColor);
              }
              SpannableStringBuilder builder = new SpannableStringBuilder();
              for (CharSequence l : CharSequenceUtils.split(styledBody, '\n')) {
                  if (l.length() > 0) {
                      if (l.toString().equals("```")) {
                          continue;
                      }
                      char first = l.charAt(0);
                      if ((first != '>' || !isPositionFollowedByQuoteableCharacter(l, 0)) && first != '\u00bb') {
                          CharSequence line = CharSequenceUtils.trim(l);
                          if (line.length() == 0) {
                              continue;
                          }
                          char last = line.charAt(line.length() - 1);
                          if (builder.length() != 0) {
                              builder.append(' ');
                          }
                          builder.append(line);
                          if (!PUNCTIONATION.contains(last)) {
                              break;
                          }
                      }
                  }
              }
              if (builder.length() == 0) {
                  builder.append(body.trim());
              }
              return new Pair<>(builder, false);
          }
      }
  }
 
Example 15
Source File: AboutPreference.java    From Conversations with GNU General Public License v3.0 4 votes vote down vote up
public AboutPreference(final Context context, final AttributeSet attrs) {
	super(context, attrs);
	final String appName = context.getString(R.string.app_name);
	setSummary(appName +' '+ PhoneHelper.getVersionName(context));
	setTitle(context.getString(R.string.title_activity_about_x, appName));
}
 
Example 16
Source File: ResUtils.java    From Qiitanium with MIT License 4 votes vote down vote up
public static String getString(Context ctx, @StringRes int stringResId) {
  return ctx.getString(stringResId);
}
 
Example 17
Source File: DialogOptions.java    From AppPlus with MIT License 4 votes vote down vote up
public String getPositiveText(Context context) {
    if (positiveText == null) {
        return context.getString(textPositiveResId);
    }
    return positiveText;
}
 
Example 18
Source File: SyncUtil.java    From earth with GNU General Public License v3.0 4 votes vote down vote up
private static Account makeAccount(Context context) {
    return new Account(context.getString(R.string.free_account), StubAuthenticator.ACCOUNT_TYPE);
}
 
Example 19
Source File: SwitchAccessPreferenceUtils.java    From talkback with Apache License 2.0 2 votes vote down vote up
/**
 * Check if linear scanning is enabled.
 *
 * @param context The current context
 * @return {@code true} if linear scanning is enabled in the preferences
 */
public static boolean isLinearScanningEnabled(Context context) {
  String linearScanningKey = context.getString(R.string.linear_scanning_key);
  String scanPref = getCurrentScanningMethod(context);
  return TextUtils.equals(scanPref, linearScanningKey);
}
 
Example 20
Source File: VersionInfoUtils.java    From android-versioninfo with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the formatted version. To be used outside the dialog fragment, for instance
 * in activity or preference titles.
 *
 * @param context The almighty context
 * @param packageName The app's package name
 * @param version The app's version
 * @return Version string
 */
public static String getFormattedVersion(final Context context, final String packageName, final String version) {
    int versionInfoStringId = context.getResources().getIdentifier("version_template", "string", packageName);
    return context.getString(versionInfoStringId, version);
}