Example usage for android.content Context getText

List of usage examples for android.content Context getText

Introduction

In this page you can find the example usage for android.content Context getText.

Prototype

@NonNull
public final CharSequence getText(@StringRes int resId) 

Source Link

Document

Return a localized, styled CharSequence from the application's package's default string table.

Usage

From source file:com.prey.net.PreyWebServices.java

public String deleteDevice(Context ctx) throws PreyException {
    PreyConfig preyConfig = PreyConfig.getPreyConfig(ctx);
    HashMap<String, String> parameters = new HashMap<String, String>();
    String xml;/*w w w.j  a v  a 2 s  .  c o  m*/
    try {
        String url = this.getDeviceWebControlPanelUiUrl(ctx);
        PreyHttpResponse response = PreyRestHttpClient.getInstance(ctx).delete(url, parameters, preyConfig);
        PreyLogger.d(response.toString());
        xml = response.getResponseAsString();

    } catch (IOException e) {
        throw new PreyException(ctx.getText(R.string.error_communication_exception).toString(), e);
    }
    return xml;
}

From source file:com.anysoftkeyboard.addons.AddOnsFactory.java

@VisibleForTesting
AddOnsFactory(@NonNull Context context, String tag, String receiverInterface, String receiverMetaData,
        String rootNodeTag, String addonNodeTag, @NonNull String prefIdPrefix, @XmlRes int buildInAddonResId,
        @StringRes int defaultAddOnStringId, boolean readExternalPacksToo, boolean isDebugBuild) {
    mContext = context;/*from   w w w .  ja v  a2 s  .com*/
    mTag = tag;
    mReceiverInterface = receiverInterface;
    mReceiverMetaData = receiverMetaData;
    mRootNodeTag = rootNodeTag;
    mAddonNodeTag = addonNodeTag;
    if (TextUtils.isEmpty(prefIdPrefix))
        throw new IllegalArgumentException("prefIdPrefix can not be empty!");
    mPrefIdPrefix = prefIdPrefix;
    mBuildInAddOnsResId = buildInAddonResId;
    mReadExternalPacksToo = readExternalPacksToo;
    mDevAddOnsIncluded = isDebugBuild;
    mDefaultAddOnId = defaultAddOnStringId == 0 ? null : context.getText(defaultAddOnStringId);
    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
}

From source file:com.google.android.apps.muzei.notifications.NewWallpaperNotificationReceiver.java

/**
 * Create the notification channel for the New Wallpaper notification
 * @return False only in the case where the user had wallpapers disabled in-app, but has not
 * yet seen the 'Review your notification settings' notification
 *///from w  ww. j av a 2  s .  c  o  m
@RequiresApi(api = Build.VERSION_CODES.O)
static boolean createNotificationChannel(Context context) {
    NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    // On O+ devices, we want to push users to change the system notification setting
    // but we'll use their current value to set the default importance
    int defaultImportance = sp.getBoolean(PREF_ENABLED, true) ? NotificationManager.IMPORTANCE_MIN
            : NotificationManager.IMPORTANCE_NONE;
    if (sp.contains(PREF_ENABLED)) {
        sp.edit().remove(PREF_ENABLED).apply();
        if (defaultImportance == NotificationManager.IMPORTANCE_NONE) {
            // Check to see if there was already a channel and give users an
            // easy way to review their notification settings if they had
            // previously disabled notifications but have not yet disabled
            // the channel
            NotificationChannel existingChannel = notificationManager
                    .getNotificationChannel(NOTIFICATION_CHANNEL);
            if (existingChannel != null
                    && existingChannel.getImportance() != NotificationManager.IMPORTANCE_NONE) {
                // Construct an Intent to get to the notification settings screen
                Intent settingsIntent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
                settingsIntent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
                settingsIntent.putExtra(Settings.EXTRA_CHANNEL_ID,
                        NewWallpaperNotificationReceiver.NOTIFICATION_CHANNEL);
                // Build the notification
                NotificationCompat.Builder builder = new NotificationCompat.Builder(context,
                        NOTIFICATION_CHANNEL).setSmallIcon(R.drawable.ic_stat_muzei)
                                .setColor(ContextCompat.getColor(context, R.color.notification))
                                .setAutoCancel(true)
                                .setContentTitle(context.getText(R.string.notification_settings_moved_title))
                                .setContentText(context.getText(R.string.notification_settings_moved_text))
                                .setContentIntent(PendingIntent.getActivity(context, 0, settingsIntent,
                                        PendingIntent.FLAG_UPDATE_CURRENT))
                                .setStyle(new NotificationCompat.BigTextStyle()
                                        .bigText(context.getText(R.string.notification_settings_moved_text)));
                notificationManager.notify(1, builder.build());
                return false;
            }
        }
    }
    NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL,
            context.getString(R.string.notification_new_wallpaper_channel_name), defaultImportance);
    channel.setShowBadge(false);
    notificationManager.createNotificationChannel(channel);
    return true;
}

From source file:com.android.messaging.datamodel.BugleNotifications.java

static CharSequence formatAttachmentTag(final String author, final String attachmentType) {
    final Context context = Factory.get().getApplicationContext();
    final TextAppearanceSpan notificationSecondaryText = new TextAppearanceSpan(context,
            R.style.NotificationSecondaryText);
    final SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
    if (!TextUtils.isEmpty(author)) {
        final TextAppearanceSpan notificationSenderSpan = new TextAppearanceSpan(context,
                R.style.NotificationSenderText);
        spannableStringBuilder.append(author);
        spannableStringBuilder.setSpan(notificationSenderSpan, 0, author.length(), 0);
        final String separator = context.getString(R.string.notification_separator);
        spannableStringBuilder.append(separator);
    }/*from   w w  w  .j  a  v a2  s  .  com*/
    final int start = spannableStringBuilder.length();
    // The default attachment type is an image, since that's what was originally
    // supported. When there's no content type, assume it's an image.
    int message = R.string.notification_picture;
    if (ContentType.isAudioType(attachmentType)) {
        message = R.string.notification_audio;
    } else if (ContentType.isVideoType(attachmentType)) {
        message = R.string.notification_video;
    } else if (ContentType.isVCardType(attachmentType)) {
        message = R.string.notification_vcard;
    }
    spannableStringBuilder.append(context.getText(message));
    spannableStringBuilder.setSpan(notificationSecondaryText, start, spannableStringBuilder.length(), 0);
    return spannableStringBuilder;
}

From source file:br.com.carlosrafaelgn.fplay.ActivityBrowserRadio.java

@Override
public void onClick(View view) {
    if (view == btnGoBack) {
        if (isAtFavorites) {
            isAtFavorites = false;/*from   w w w .j  a v  a2s.co m*/
            doSearch();
        } else {
            finish(0, view, true);
        }
    } else if (view == btnFavorite) {
        isAtFavorites = true;
        radioStationList.cancel();
        radioStationList.fetchFavorites(getApplication());
        updateButtons();
    } else if (view == btnSearch) {
        final Context ctx = getHostActivity();
        final LinearLayout l = (LinearLayout) UI.createDialogView(ctx, null);

        LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        chkGenre = new RadioButton(ctx);
        chkGenre.setText(R.string.genre);
        chkGenre.setChecked(Player.lastRadioSearchWasByGenre);
        chkGenre.setOnClickListener(this);
        chkGenre.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._DLGsp);
        chkGenre.setLayoutParams(p);

        p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        p.topMargin = UI._DLGsppad;
        btnGenre = new Spinner(ctx);
        btnGenre.setContentDescription(ctx.getText(R.string.genre));
        btnGenre.setLayoutParams(p);

        p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        p.topMargin = UI._DLGsppad << 1;
        chkTerm = new RadioButton(ctx);
        chkTerm.setText(R.string.search_term);
        chkTerm.setChecked(!Player.lastRadioSearchWasByGenre);
        chkTerm.setOnClickListener(this);
        chkTerm.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._DLGsp);
        chkTerm.setLayoutParams(p);

        p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        p.topMargin = UI._DLGsppad;
        txtTerm = new EditText(ctx);
        txtTerm.setContentDescription(ctx.getText(R.string.search_term));
        txtTerm.setText(Player.radioSearchTerm == null ? "" : Player.radioSearchTerm);
        txtTerm.setOnClickListener(this);
        txtTerm.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._DLGsp);
        txtTerm.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
        txtTerm.setSingleLine();
        txtTerm.setLayoutParams(p);

        p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        p.topMargin = UI._DLGsppad;
        p.bottomMargin = UI._DLGsppad;
        final TextView lbl = new TextView(ctx);
        lbl.setAutoLinkMask(0);
        lbl.setLinksClickable(true);
        //http://developer.android.com/design/style/color.html
        lbl.setLinkTextColor(new BgColorStateList(UI.isAndroidThemeLight() ? 0xff0099cc : 0xff33b5e5));
        lbl.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._14sp);
        lbl.setGravity(Gravity.CENTER_HORIZONTAL);
        lbl.setText(SafeURLSpan.parseSafeHtml(getText(R.string.by_dir_xiph_org)));
        lbl.setMovementMethod(LinkMovementMethod.getInstance());
        lbl.setLayoutParams(p);

        l.addView(chkGenre);
        l.addView(btnGenre);
        l.addView(chkTerm);
        l.addView(txtTerm);
        l.addView(lbl);

        btnGenre.setAdapter(this);
        btnGenre.setSelection(getValidGenre(Player.radioLastGenre));
        defaultTextColors = txtTerm.getTextColors();

        UI.prepareDialogAndShow((new AlertDialog.Builder(ctx)).setTitle(getText(R.string.search)).setView(l)
                .setPositiveButton(R.string.search, this).setNegativeButton(R.string.cancel, this)
                .setOnCancelListener(this).create());
    } else if (view == btnGoBackToPlayer) {
        finish(-1, view, false);
    } else if (view == btnAdd) {
        addPlaySelectedItem(false);
    } else if (view == btnPlay) {
        addPlaySelectedItem(true);
    } else if (view == chkGenre || view == btnGenre) {
        chkGenre.setChecked(true);
        chkTerm.setChecked(false);
    } else if (view == chkTerm || view == txtTerm) {
        chkGenre.setChecked(false);
        chkTerm.setChecked(true);
    } else if (view == list) {
        if (!isAtFavorites && !loading && (radioStationList == null || radioStationList.getCount() == 0))
            onClick(btnFavorite);
    }
}

From source file:org.yuttadhammo.BodhiTimer.TimerReceiver.java

@Override
public void onReceive(Context context, Intent pintent) {
    Log.v(TAG, "ALARM: received alarm");

    NotificationManager mNM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    if (player != null) {
        Log.v(TAG, "Releasing media player...");
        try {//from w w  w  .  j  av  a  2 s . co m
            player.release();
            player = null;
        } catch (Exception e) {
            e.printStackTrace();
            player = null;
        } finally {
            // do nothing
        }
    }

    // Cancel notification and return...
    if (CANCEL_NOTIFICATION.equals(pintent.getAction())) {
        Log.v(TAG, "Cancelling notification...");

        mNM.cancelAll();
        return;
    }

    // ...or display a new one

    Log.v(TAG, "Showing notification...");

    player = new MediaPlayer();

    int setTime = pintent.getIntExtra("SetTime", 0);
    String setTimeStr = TimerUtils.time2humanStr(context, setTime);
    Log.v(TAG, "Time: " + setTime);

    CharSequence text = context.getText(R.string.Notification);
    CharSequence textLatest = String.format(context.getString(R.string.timer_for_x), setTimeStr);

    // Load the settings 
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    boolean led = prefs.getBoolean("LED", true);
    boolean vibrate = prefs.getBoolean("Vibrate", true);
    String notificationUri = "";

    boolean useAdvTime = prefs.getBoolean("useAdvTime", false);
    String advTimeString = prefs.getString("advTimeString", "");
    String[] advTime = null;
    int advTimeIndex = 1;

    if (useAdvTime && advTimeString.length() > 0) {
        advTime = advTimeString.split("\\^");
        advTimeIndex = prefs.getInt("advTimeIndex", 1);
        String[] thisAdvTime = advTime[advTimeIndex - 1].split("#"); // will be of format timeInMs#pathToSound

        if (thisAdvTime.length == 3)
            notificationUri = thisAdvTime[1];
        if (notificationUri.equals("sys_def"))
            notificationUri = prefs.getString("NotificationUri",
                    "android.resource://org.yuttadhammo.BodhiTimer/" + R.raw.bell);
    } else
        notificationUri = prefs.getString("NotificationUri",
                "android.resource://org.yuttadhammo.BodhiTimer/" + R.raw.bell);

    Log.v(TAG, "notification uri: " + notificationUri);

    if (notificationUri.equals("system"))
        notificationUri = prefs.getString("SystemUri", "");
    else if (notificationUri.equals("file"))
        notificationUri = prefs.getString("FileUri", "");
    else if (notificationUri.equals("tts")) {
        notificationUri = "";
        final String ttsString = prefs.getString("tts_string", context.getString(R.string.timer_done));
        Intent ttsIntent = new Intent(context, TTSService.class);
        ttsIntent.putExtra("spoken_text", ttsString);
        context.startService(ttsIntent);
    }

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context.getApplicationContext())
            .setSmallIcon(R.drawable.notification).setContentTitle(text).setContentText(textLatest);

    Uri uri = null;

    // Play a sound!
    if (!notificationUri.equals(""))
        uri = Uri.parse(notificationUri);

    // Vibrate
    if (vibrate && uri == null) {
        mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
    }

    // Have a light
    if (led) {
        mBuilder.setLights(0xff00ff00, 300, 1000);
    }

    mBuilder.setAutoCancel(true);

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, TimerActivity.class);

    // The stack builder object will contain an artificial back stack for the
    // started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(TimerActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    // Create intent for cancelling the notification
    Context appContext = context.getApplicationContext();
    Intent intent = new Intent(appContext, TimerReceiver.class);
    intent.setAction(CANCEL_NOTIFICATION);

    // Cancel the pending cancellation and create a new one
    PendingIntent pendingCancelIntent = PendingIntent.getBroadcast(appContext, 0, intent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    if (uri != null) {

        //remove notification sound
        mBuilder.setSound(null);

        try {
            if (player != null && player.isPlaying()) {
                player.release();
                player = new MediaPlayer();
            }

            int currVolume = prefs.getInt("tone_volume", 0);
            if (currVolume != 0) {
                float log1 = (float) (Math.log(100 - currVolume) / Math.log(100));
                player.setVolume(1 - log1, 1 - log1);
            }
            player.setDataSource(context, uri);
            player.prepare();
            player.setLooping(false);
            player.setOnCompletionListener(new OnCompletionListener() {

                @Override
                public void onCompletion(MediaPlayer mp) {
                    // TODO Auto-generated method stub
                    mp.release();
                }

            });
            player.start();
            if (vibrate) {
                Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
                vibrator.vibrate(1000);
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    if (prefs.getBoolean("AutoClear", false)) {
        // Determine duration of notification sound
        int duration = 5000;
        if (uri != null) {
            MediaPlayer cancelPlayer = new MediaPlayer();
            try {
                cancelPlayer.setDataSource(context, uri);
                cancelPlayer.prepare();
                duration = Math.max(duration, cancelPlayer.getDuration() + 2000);
            } catch (java.io.IOException ex) {
                Log.e(TAG, "Cannot get sound duration: " + ex);
                duration = 30000; // on error, default to 30 seconds
            } finally {
                cancelPlayer.release();
            }
            cancelPlayer.release();
        }
        Log.v(TAG, "Notification duration: " + duration + " ms");
        // Schedule cancellation
        AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        alarmMgr.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + duration,
                pendingCancelIntent);
    }

    if (useAdvTime && advTimeString.length() > 0) {
        Intent broadcast = new Intent();

        SharedPreferences.Editor editor = prefs.edit();
        if (advTimeIndex < advTime.length) {
            editor.putInt("advTimeIndex", advTimeIndex + 1);

            String[] thisAdvTime = advTime[advTimeIndex].split("#"); // will be of format timeInMs#pathToSound

            int time = Integer.parseInt(thisAdvTime[0]);

            broadcast.putExtra("time", time);

            // Save new time
            editor.putLong("TimeStamp", new Date().getTime() + time);
            editor.putInt("LastTime", time);

            // editor.putString("NotificationUri", thisAdvTime[1]);

            mNM.cancelAll();
            Log.v(TAG, "Starting next iteration of the timer service ...");
            Intent rintent = new Intent(context, TimerReceiver.class);
            rintent.putExtra("SetTime", time);
            PendingIntent mPendingIntent = PendingIntent.getBroadcast(context, 0, rintent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            AlarmManager mAlarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
            mAlarmMgr.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + time, mPendingIntent);
        } else {
            broadcast.putExtra("stop", true);
            editor.putInt("advTimeIndex", 1);

        }
        broadcast.setAction(BROADCAST_RESET);
        context.sendBroadcast(broadcast);

        editor.apply();

    } else if (prefs.getBoolean("AutoRestart", false)) {
        int time = pintent.getIntExtra("SetTime", 0);
        if (time != 0) {

            mNM.cancel(0);
            Log.v(TAG, "Restarting the timer service ...");
            Intent rintent = new Intent(context, TimerReceiver.class);
            rintent.putExtra("SetTime", time);
            PendingIntent mPendingIntent = PendingIntent.getBroadcast(context, 0, rintent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            AlarmManager mAlarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
            mAlarmMgr.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + time, mPendingIntent);

            // Save new time
            SharedPreferences.Editor editor = prefs.edit();
            editor.putLong("TimeStamp", new Date().getTime() + time);
            editor.putInt("LastTime", time);
            editor.apply();

            Intent broadcast = new Intent();
            broadcast.putExtra("time", time);
            broadcast.setAction(BROADCAST_RESET);
            context.sendBroadcast(broadcast);

        }
    }

    mNotificationManager.notify(0, mBuilder.build());

    Log.d(TAG, "ALARM: alarm finished");

}

From source file:com.prey.net.PreyWebServices.java

public PreyAccountData registerNewDeviceToAccount(Context ctx, String email, String password, String deviceType)
        throws PreyException {
    PreyLogger.d("email:" + email + " password:" + password);
    PreyConfig preyConfig = PreyConfig.getPreyConfig(ctx);
    HashMap<String, String> parameters = new HashMap<String, String>();
    PreyHttpResponse response = null;/*  w w w.j  a  v a 2  s .  c  o  m*/
    String xml;
    try {
        String apiv2 = FileConfigReader.getInstance(ctx).getApiV2();
        String url = PreyConfig.getPreyConfig(ctx).getPreyUrl().concat(apiv2).concat("profile.xml");
        PreyLogger.d("url:" + url);
        response = PreyRestHttpClient.getInstance(ctx).get(url, parameters, preyConfig, email, password);
        xml = response.getResponseAsString();
    } catch (IOException e) {
        PreyLogger.e("Error!", e);
        throw new PreyException(ctx.getText(R.string.error_communication_exception).toString(), e);
    }
    String status = "";
    if (response != null && response.getStatusLine() != null) {
        status = "[" + response.getStatusLine().getStatusCode() + "]";
    }
    if (!xml.contains("<key")) {
        throw new PreyException(ctx.getString(R.string.error_cant_add_this_device, status));
    }

    int from;
    int to;
    String apiKey;
    try {
        from = xml.indexOf("<key>") + 5;
        to = xml.indexOf("</key>");
        apiKey = xml.substring(from, to);
    } catch (Exception e) {
        throw new PreyException(ctx.getString(R.string.error_cant_add_this_device, status));
    }
    String deviceId = null;
    PreyHttpResponse responseDevice = registerNewDevice(ctx, apiKey, deviceType);
    String xmlDeviceId = responseDevice.getResponseAsString();
    //if json
    if (xmlDeviceId.contains("{\"key\"")) {
        try {
            JSONObject jsnobject = new JSONObject(xmlDeviceId);
            deviceId = jsnobject.getString("key");
        } catch (Exception e) {

        }
    }
    PreyAccountData newAccount = new PreyAccountData();
    newAccount.setApiKey(apiKey);
    newAccount.setDeviceId(deviceId);
    newAccount.setEmail(email);
    newAccount.setPassword(password);
    return newAccount;

}

From source file:org.totschnig.myexpenses.util.Utils.java

/**
 * @param ctx/*www .j  a v a 2s . c o  m*/
 *          for retrieving resources
 * @param other
 *          if not null, all features except the one provided will be returned
 * @param type if not null, only features of this type will be listed
 * @return construct a list of all contrib features to be included into a
 *         TextView
 */
public static CharSequence getContribFeatureLabelsAsFormattedList(Context ctx, ContribFeature other,
        LicenceHandler.LicenceStatus type) {
    CharSequence result = "", linefeed = Html.fromHtml("<br>");
    Iterator<ContribFeature> iterator = EnumSet.allOf(ContribFeature.class).iterator();
    while (iterator.hasNext()) {
        ContribFeature f = iterator.next();
        if (!f.equals(other) && (!f.equals(ContribFeature.AD_FREE) || IS_FLAVOURED)) {
            if (type != null && ((f.isExtended() && !type.equals(LicenceHandler.LicenceStatus.EXTENDED))
                    || (!f.isExtended() && type.equals(LicenceHandler.LicenceStatus.EXTENDED)))) {
                continue;
            }
            String resName = "contrib_feature_" + f.toString() + "_label";
            int resId = ctx.getResources().getIdentifier(resName, "string", ctx.getPackageName());
            if (resId == 0) {
                AcraHelper.report(new Resources.NotFoundException(resName));
                continue;
            }
            if (!result.equals("")) {
                result = TextUtils.concat(result, linefeed);
            }
            result = TextUtils.concat(result, "\u25b6 ", ctx.getText(resId));
        }
    }
    return result;
}

From source file:org.zoumbox.mh_dla_notifier.Receiver.java

protected void displayNotification(Context context, NotificationType type, CharSequence title,
        CharSequence text, Pair<Boolean, Boolean> soundAndVibrate) {

    // The PendingIntent to launch our activity if the user selects this notification
    Intent mainActivity = new Intent(context, MainActivity.class);
    mainActivity.putExtra(MainActivity.EXTRA_FROM_NOTIFICATION, true);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, mainActivity, 0);

    Intent playIntent = MhDlaNotifierUtils.GET_PLAY_INTENT.apply(context);
    PendingIntent playPendingIntent = PendingIntent.getActivity(context, 0, playIntent, 0);
    long now = System.currentTimeMillis();

    Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(),
            R.drawable.trarnoll_square_transparent_128);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setOnlyAlertOnce(true)
            .setLights(Color.YELLOW, 1500, 1500).setSmallIcon(R.drawable.trarnoll_square_transparent_128)
            .setLargeIcon(largeIcon).setContentTitle(title).setContentText(text).setWhen(now)
            .setContentIntent(contentIntent).setAutoCancel(true).setTicker(title)
            .addAction(R.drawable.ic_action_play, context.getText(R.string.play), playPendingIntent);

    if (soundAndVibrate.left()) {
        Uri defaultSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        builder.setSound(defaultSound);/*from  ww w .j  av  a  2s.  c o  m*/
    }

    if (soundAndVibrate.right()) {
        builder.setVibrate(VIBRATE_PATTERN);
    } else {
        builder.setVibrate(NO_VIBRATION);
    }

    Notification notification = builder.build();

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    int notifId = type.name().hashCode();
    notificationManager.notify(notifId, notification);
}

From source file:cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.data.receiver.NotificationHelper.java

/**
 * Needs the builder that contains non-note specific values.
 *
 *//*from w  w w  . j  av a2s .c  o m*/
private static void notifyBigText(final Context context, final NotificationManager notificationManager,
        final NotificationCompat.Builder builder,
        final cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.data.model.sql.Notification note) {
    final Intent delIntent = new Intent(Intent.ACTION_DELETE, note.getUri());
    if (note.repeats != 0) {
        delIntent.setAction(ACTION_RESCHEDULE);
    }
    // Add extra so we don't delete all
    // if (note.time != null) {
    // delIntent.putExtra(ARG_MAX_TIME, note.time);
    // }
    delIntent.putExtra(ARG_TASKID, note.taskID);
    // Delete it on clear
    PendingIntent deleteIntent = PendingIntent.getBroadcast(context, 0, delIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Open intent
    final Intent openIntent = new Intent(Intent.ACTION_VIEW, Task.getUri(note.taskID));
    // Should create a new instance to avoid fragment problems
    openIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);

    // Delete intent on non-location repeats
    // Opening the note should delete/reschedule the notification
    openIntent.putExtra(NOTIFICATION_DELETE_ARG, note._id);

    // Opening always cancels the notification though
    openIntent.putExtra(NOTIFICATION_CANCEL_ARG, note._id);

    // Open note on click
    PendingIntent clickIntent = PendingIntent.getActivity(context, 0, openIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Action to complete
    PendingIntent completeIntent = PendingIntent.getBroadcast(context, 0,
            new Intent(ACTION_COMPLETE, note.getUri()).putExtra(ARG_TASKID, note.taskID),
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Action to snooze
    PendingIntent snoozeIntent = PendingIntent.getBroadcast(context, 0,
            new Intent(ACTION_SNOOZE, note.getUri()).putExtra(ARG_TASKID, note.taskID),
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Build notification
    builder.setContentTitle(note.taskTitle).setContentText(note.taskNote).setContentIntent(clickIntent)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(note.taskNote));

    // Delete intent on non-location repeats
    builder.setDeleteIntent(deleteIntent);

    // Snooze button only on time non-repeating
    if (note.time != null && note.repeats == 0) {
        builder.addAction(R.drawable.ic_alarm_24dp_white, context.getText(R.string.snooze), snoozeIntent);
    }
    // Complete button only on non-repeating, both time and location
    if (note.repeats == 0) {
        builder.addAction(R.drawable.ic_check_24dp_white, context.getText(R.string.completed), completeIntent);
    }

    final Notification noti = builder.build();

    notificationManager.notify((int) note._id, noti);
}