Search in sources :

Example 76 with Builder

use of android.support.v4.app.NotificationCompat.Builder in project NetGuard by M66B.

the class ServiceSinkhole method showErrorNotification.

private void showErrorNotification(String message) {
    Intent main = new Intent(this, ActivityMain.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);
    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_error_white_24dp).setContentTitle(getString(R.string.app_name)).setContentText(getString(R.string.msg_error, message)).setContentIntent(pi).setColor(tv.data).setOngoing(false).setAutoCancel(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
    }
    NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
    notification.bigText(getString(R.string.msg_error, message));
    notification.setSummaryText(message);
    NotificationManagerCompat.from(this).notify(NOTIFY_ERROR, notification.build());
}
Also used : NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) TypedValue(android.util.TypedValue)

Example 77 with Builder

use of android.support.v4.app.NotificationCompat.Builder in project Talon-for-Twitter by klinker24.

the class TweetPager method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case android.R.id.home:
            onBackPressed();
            return true;
        case R.id.menu_save_tweet:
            saveTweet();
            return true;
        case R.id.menu_remove_saved_tweet:
            removeSavedTweet();
            return true;
        case R.id.menu_delete_tweet:
            new DeleteTweet().execute();
            getSharedPreferences("com.klinker.android.twitter_world_preferences", 0).edit().putBoolean("just_muted", true).commit();
            return true;
        case R.id.menu_share:
            String text1 = tweet;
            text1 = "@" + screenName + ": " + text1 + "\n\n" + "https://twitter.com/" + screenName + "/status/" + tweetId;
            Log.v("my_text_on_share", text1);
            Intent share = new Intent(Intent.ACTION_SEND);
            share.setType("text/plain");
            share.putExtra(Intent.EXTRA_TEXT, text1);
            startActivity(share);
            return true;
        case R.id.menu_copy_text:
            ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("tweet_text", tweet);
            clipboard.setPrimaryClip(clip);
            return true;
        case R.id.menu_save_image:
            new Thread(new Runnable() {

                @Override
                public void run() {
                    Looper.prepare();
                    try {
                        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, TALON_SERVICE_CHANNEL_ID).setSmallIcon(R.drawable.ic_stat_icon).setTicker(getResources().getString(R.string.downloading) + "...").setContentTitle(getResources().getString(R.string.app_name)).setContentText(getResources().getString(R.string.saving_picture) + "...").setProgress(100, 100, true).setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_action_save));
                        NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
                        mNotificationManager.notify(6, mBuilder.build());
                        String url = webpage;
                        if (webpage.contains("insta")) {
                            url = url.substring(0, url.length() - 1) + "l";
                        }
                        URL mUrl = new URL(url);
                        Bitmap bitmap = BitmapFactory.decodeStream(mUrl.openConnection().getInputStream());
                        Random generator = new Random();
                        int n = 1000000;
                        n = generator.nextInt(n);
                        String fname = "Image-" + n;
                        Uri uri = IOUtils.saveImage(bitmap, fname, context);
                        Intent intent = new Intent();
                        intent.setAction(Intent.ACTION_VIEW);
                        intent.setDataAndType(uri, "image/*");
                        PendingIntent pending = PendingIntent.getActivity(context, 91, intent, 0);
                        mBuilder = new NotificationCompat.Builder(context, TALON_SERVICE_CHANNEL_ID).setContentIntent(pending).setSmallIcon(R.drawable.ic_stat_icon).setTicker(getResources().getString(R.string.saved_picture) + "...").setContentTitle(getResources().getString(R.string.app_name)).setContentText(getResources().getString(R.string.saved_picture) + "!").setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_action_save));
                        mNotificationManager.notify(6, mBuilder.build());
                    } catch (Exception e) {
                        e.printStackTrace();
                        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, TALON_SERVICE_CHANNEL_ID).setSmallIcon(R.drawable.ic_stat_icon).setTicker(getResources().getString(R.string.error) + "...").setContentTitle(getResources().getString(R.string.app_name)).setContentText(getResources().getString(R.string.error) + "...").setProgress(100, 100, true).setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_action_save));
                        NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
                        mNotificationManager.notify(6, mBuilder.build());
                    }
                }
            }).start();
            return true;
        case R.id.menu_quote:
            String text = tweet;
            switch(settings.quoteStyle) {
                case AppSettings.QUOTE_STYLE_TWITTER:
                    text = " " + "https://twitter.com/" + screenName + "/status/" + tweetId;
                    break;
                case AppSettings.QUOTE_STYLE_TALON:
                    text = "\"@" + screenName + ": " + text + "\" ";
                    break;
                case AppSettings.QUOTE_STYLE_RT:
                    text = " RT @" + screenName + ": " + text;
                    break;
            }
            Intent quote = new Intent(context, ComposeActivity.class);
            quote.putExtra("user", text);
            quote.putExtra("id", tweetId);
            startActivity(quote);
            return true;
        case R.id.menu_spam:
            new MarkSpam().execute();
            getSharedPreferences("com.klinker.android.twitter_world_preferences", 0).edit().putBoolean("just_muted", true).commit();
            return super.onOptionsItemSelected(item);
        /*case R.id.menu_mute_hashtags:
                if (!hashtags[0].equals("")) {
                    ArrayList<String> tags = new ArrayList<String>();
                    if (hashtags != null) {
                        for (String s : hashtags) {
                            if (!s.equals("")) {
                                tags.add("#" + s);
                            }
                        }
                    }

                    final CharSequence[] fItems = new CharSequence[tags.size()];

                    for (int i = 0; i < tags.size(); i++) {
                        fItems[i] = tags.get(i);
                    }

                    final SharedPreferences sharedPreferences = context.getSharedPreferences("com.klinker.android.twitter_world_preferences",
                            0);

                    if (fItems.length > 1) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(context);
                        builder.setItems(fItems, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int item) {
                                String touched = fItems[item] + "";
                                Toast.makeText(context, getResources().getString(R.string.muted) + " " + touched, Toast.LENGTH_SHORT).show();
                                touched = touched.replace("#", "") + " ";

                                String current = sharedPreferences.getString("muted_hashtags", "");
                                sharedPreferences.edit().putString("muted_hashtags", current + touched).commit();
                                sharedPreferences.edit().putBoolean("refresh_me", true).commit();

                                dialog.dismiss();
                            }
                        });
                        AlertDialog alert = builder.create();
                        alert.show();
                    } else {
                        String touched = fItems[0] + "";
                        Toast.makeText(context, getResources().getString(R.string.muted) + " " + touched, Toast.LENGTH_SHORT).show();
                        touched = touched.replace("#", "") + " ";

                        String current = sharedPreferences.getString("muted_hashtags", "");
                        sharedPreferences.edit().putString("muted_hashtags", current + touched).commit();
                        sharedPreferences.edit().putBoolean("refresh_me", true).commit();

                    }
                } else {
                    Toast.makeText(context, getResources().getString(R.string.no_hashtags), Toast.LENGTH_SHORT).show();
                }

                PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("just_muted", true).commit();
                return super.onOptionsItemSelected(item);

            case R.id.menu_share_links:
                if (!otherLinks[0].equals("")) {
                    ArrayList<String> urls = new ArrayList<String>();
                    if (otherLinks != null) {
                        for (String s : otherLinks) {
                            if (!s.equals("")) {
                                urls.add(s);
                            }
                        }
                    }

                    final CharSequence[] fItems = new CharSequence[urls.size()];

                    for (int i = 0; i < urls.size(); i++) {
                        fItems[i] = urls.get(i);
                    }

                    if (fItems.length > 1) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(context);
                        builder.setItems(fItems, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int item) {
                                String touched = fItems[item] + "";

                                Intent intent=new Intent(android.content.Intent.ACTION_SEND);
                                intent.setType("text/plain");
                                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                                intent.putExtra(Intent.EXTRA_TEXT, touched);
                                context.startActivity(Intent.createChooser(intent, context.getResources().getString(R.string.menu_share)));

                                dialog.dismiss();
                            }
                        });
                        AlertDialog alert = builder.create();
                        alert.show();
                    } else {
                        String touched = fItems[0] + "";

                        Intent intent=new Intent(android.content.Intent.ACTION_SEND);
                        intent.setType("text/plain");
                        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                        intent.putExtra(Intent.EXTRA_TEXT, touched);
                        context.startActivity(Intent.createChooser(intent, context.getResources().getString(R.string.menu_share)));
                    }
                } else {
                    Toast.makeText(context, getResources().getString(R.string.no_links), Toast.LENGTH_SHORT).show();
                }
                return super.onOptionsItemSelected(item);*/
        case R.id.menu_translate:
            try {
                String url = settings.translateURL + tweet;
                Uri uri = Uri.parse(url);
                Intent browser = new Intent(Intent.ACTION_VIEW, uri);
                browser.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(browser);
            } catch (Exception e) {
            }
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
Also used : NotificationManager(android.app.NotificationManager) PendingIntent(android.app.PendingIntent) Uri(android.net.Uri) URL(java.net.URL) Point(android.graphics.Point) Bitmap(android.graphics.Bitmap) Random(java.util.Random) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent)

Example 78 with Builder

use of android.support.v4.app.NotificationCompat.Builder in project aware-client by denzilferreira.

the class ESM_DateTime method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    super.onCreateDialog(savedInstanceState);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    datePicked = Calendar.getInstance();
    View ui = inflater.inflate(R.layout.esm_datetime, null);
    builder.setView(ui);
    esm_dialog = builder.create();
    esm_dialog.setCanceledOnTouchOutside(false);
    try {
        TextView esm_title = (TextView) ui.findViewById(R.id.esm_title);
        esm_title.setText(getTitle());
        TextView esm_instructions = (TextView) ui.findViewById(R.id.esm_instructions);
        esm_instructions.setText(getInstructions());
        final ViewPager datetimePager = (ViewPager) ui.findViewById(R.id.datetimepager);
        DateTimePagerAdapter dateTimePagerAdapter = new DateTimePagerAdapter(getContext());
        datetimePager.setAdapter(dateTimePagerAdapter);
        datetimePager.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                try {
                    if (getExpirationThreshold() > 0 && expire_monitor != null)
                        expire_monitor.cancel(true);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
        Button cancel_text = (Button) ui.findViewById(R.id.esm_cancel);
        cancel_text.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                esm_dialog.cancel();
            }
        });
        Button submit_number = (Button) ui.findViewById(R.id.esm_submit);
        submit_number.setText(getSubmitButton());
        submit_number.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                try {
                    if (getExpirationThreshold() > 0 && expire_monitor != null)
                        expire_monitor.cancel(true);
                    ContentValues rowData = new ContentValues();
                    rowData.put(ESM_Provider.ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis());
                    rowData.put(ESM_Provider.ESM_Data.ANSWER, datePicked.getTimeInMillis());
                    rowData.put(ESM_Provider.ESM_Data.STATUS, ESM.STATUS_ANSWERED);
                    getActivity().getContentResolver().update(ESM_Provider.ESM_Data.CONTENT_URI, rowData, ESM_Provider.ESM_Data._ID + "=" + getID(), null);
                    Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED);
                    answer.putExtra(ESM.EXTRA_ANSWER, rowData.getAsString(ESM_Provider.ESM_Data.ANSWER));
                    getActivity().sendBroadcast(answer);
                    if (Aware.DEBUG)
                        Log.d(Aware.TAG, "Answer:" + rowData.toString());
                    esm_dialog.dismiss();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return esm_dialog;
}
Also used : AlertDialog(android.app.AlertDialog) ContentValues(android.content.ContentValues) JSONException(org.json.JSONException) Intent(android.content.Intent) View(android.view.View) TextView(android.widget.TextView) ViewPager(android.support.v4.view.ViewPager) Button(android.widget.Button) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) NonNull(android.support.annotation.NonNull)

Example 79 with Builder

use of android.support.v4.app.NotificationCompat.Builder in project Shuttle by timusus.

the class PlaylistUtils method renamePlaylistDialog.

public static void renamePlaylistDialog(final Context context, final Playlist playlist) {
    @SuppressLint("InflateParams") View customView = LayoutInflater.from(context).inflate(R.layout.dialog_playlist, null);
    final EditText editText = customView.findViewById(R.id.editText);
    editText.setText(playlist.name);
    MaterialDialog.Builder builder = DialogUtils.getBuilder(context).title(R.string.create_playlist_create_text_prompt).customView(customView, false).positiveText(R.string.save).onPositive((materialDialog, dialogAction) -> {
        String name = editText.getText().toString();
        if (name.length() > 0) {
            ContentResolver resolver = context.getContentResolver();
            ContentValues values = new ContentValues(1);
            values.put(MediaStore.Audio.Playlists.NAME, name);
            resolver.update(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, values, MediaStore.Audio.Playlists._ID + "=?", new String[] { Long.valueOf(playlist.id).toString() });
            playlist.name = name;
            Toast.makeText(context, R.string.playlist_renamed_message, Toast.LENGTH_SHORT).show();
        }
    }).negativeText(R.string.cancel);
    final MaterialDialog dialog = builder.build();
    TextWatcher textWatcher = new TextWatcher() {

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // check if playlist with current name exists already, and warn the user if so.
            setSaveButton(dialog, playlist, editText.getText().toString());
        }

        public void afterTextChanged(Editable s) {
        }
    };
    editText.addTextChangedListener(textWatcher);
    dialog.show();
}
Also used : EditText(android.widget.EditText) R(com.simplecity.amp_library.R) Spannable(android.text.Spannable) Completable(io.reactivex.Completable) Uri(android.net.Uri) PlayCountTable(com.simplecity.amp_library.sql.providers.PlayCountTable) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) Song(com.simplecity.amp_library.model.Song) Optional(com.annimon.stream.Optional) CheckBox(android.widget.CheckBox) ContentResolver(android.content.ContentResolver) MediaStore(android.provider.MediaStore) View(android.view.View) Schedulers(io.reactivex.schedulers.Schedulers) Log(android.util.Log) Playlist(com.simplecity.amp_library.model.Playlist) SubMenu(android.view.SubMenu) Query(com.simplecity.amp_library.model.Query) List(java.util.List) TextView(android.widget.TextView) ContentValues(android.content.ContentValues) Nullable(android.support.annotation.Nullable) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) SqlUtils(com.simplecity.amp_library.sql.SqlUtils) TextWatcher(android.text.TextWatcher) FileType(com.simplecity.amp_library.interfaces.FileType) Context(android.content.Context) Stream(com.annimon.stream.Stream) Environment(android.os.Environment) Dialog(android.app.Dialog) Intent(android.content.Intent) NonNull(android.support.annotation.NonNull) Single(io.reactivex.Single) Editable(android.text.Editable) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) SpannableStringBuilder(android.text.SpannableStringBuilder) Toast(android.widget.Toast) BaseFileObject(com.simplecity.amp_library.model.BaseFileObject) Observable(io.reactivex.Observable) UnsafeConsumer(com.simplecity.amp_library.rx.UnsafeConsumer) Cursor(android.database.Cursor) SqlBriteUtils(com.simplecity.amp_library.sql.sqlbrite.SqlBriteUtils) LayoutInflater(android.view.LayoutInflater) StyleSpan(android.text.style.StyleSpan) FileWriter(java.io.FileWriter) ProgressDialog(android.app.ProgressDialog) TextUtils(android.text.TextUtils) DialogAction(com.afollestad.materialdialogs.DialogAction) IOException(java.io.IOException) WorkerThread(android.support.annotation.WorkerThread) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) Pair(android.support.v4.util.Pair) Crashlytics(com.crashlytics.android.Crashlytics) Collections(java.util.Collections) EditText(android.widget.EditText) ContentUris(android.content.ContentUris) ContentValues(android.content.ContentValues) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) SuppressLint(android.annotation.SuppressLint) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) View(android.view.View) TextView(android.widget.TextView) ContentResolver(android.content.ContentResolver)

Example 80 with Builder

use of android.support.v4.app.NotificationCompat.Builder in project BottomNavigation by Ashok-Varma.

the class BadgeItem method hide.

/**
 * @param animate whether to animate the change
 * @return this, to allow builder pattern
 */
public T hide(boolean animate) {
    mIsHidden = true;
    if (isWeakReferenceValid()) {
        TextView textView = mTextViewRef.get();
        if (animate) {
            ViewPropertyAnimatorCompat animatorCompat = ViewCompat.animate(textView);
            animatorCompat.cancel();
            animatorCompat.setDuration(mAnimationDuration);
            animatorCompat.scaleX(0).scaleY(0);
            animatorCompat.setListener(new ViewPropertyAnimatorListener() {

                @Override
                public void onAnimationStart(View view) {
                // Empty body
                }

                @Override
                public void onAnimationEnd(View view) {
                    view.setVisibility(View.GONE);
                }

                @Override
                public void onAnimationCancel(View view) {
                    view.setVisibility(View.GONE);
                }
            });
            animatorCompat.start();
        } else {
            textView.setVisibility(View.GONE);
        }
    }
    return getSubInstance();
}
Also used : ViewPropertyAnimatorListener(android.support.v4.view.ViewPropertyAnimatorListener) TextView(android.widget.TextView) ViewPropertyAnimatorCompat(android.support.v4.view.ViewPropertyAnimatorCompat) TextView(android.widget.TextView) View(android.view.View)

Aggregations

NotificationCompat (android.support.v4.app.NotificationCompat)109 PendingIntent (android.app.PendingIntent)89 Intent (android.content.Intent)82 NotificationManager (android.app.NotificationManager)36 Notification (android.app.Notification)31 Builder (android.support.v4.app.NotificationCompat.Builder)19 Context (android.content.Context)18 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)15 Uri (android.net.Uri)14 Bundle (android.os.Bundle)13 View (android.view.View)13 TextView (android.widget.TextView)11 Bitmap (android.graphics.Bitmap)10 IOException (java.io.IOException)10 RemoteViews (android.widget.RemoteViews)9 ArrayList (java.util.ArrayList)9 AlertDialog (android.app.AlertDialog)8 DialogInterface (android.content.DialogInterface)7 Dialog (android.app.Dialog)6 Paint (android.graphics.Paint)6