Search in sources :

Example 66 with Builder

use of android.support.v4.app.NotificationCompat.Builder in project Android-IMSI-Catcher-Detector by CellularPrivacy.

the class Helpers method getOpenCellData.

public static void getOpenCellData(InjectionAppCompatActivity injectionActivity, Cell cell, char type, final AimsicdService service) {
    if (Helpers.isNetAvailable(injectionActivity)) {
        if (!"NA".equals(CellTracker.OCID_API_KEY)) {
            // [Km]
            double earthRadius = 6371.01;
            // Use a 2 Km radius with center at GPS location.
            int radius = 2;
            if (Double.doubleToRawLongBits(cell.getLat()) != 0 && Double.doubleToRawLongBits(cell.getLon()) != 0) {
                //New GeoLocation object to find bounding Coordinates
                GeoLocation currentLoc = GeoLocation.fromDegrees(cell.getLat(), cell.getLon());
                //Calculate the Bounding Box Coordinates using an N Km "radius" //0=min, 1=max
                GeoLocation[] boundingCoords = currentLoc.boundingCoordinates(radius, earthRadius);
                String boundParameter;
                //Request OpenCellID data for Bounding Coordinates (0 = min, 1 = max)
                boundParameter = String.valueOf(boundingCoords[0].getLatitudeInDegrees()) + "," + String.valueOf(boundingCoords[0].getLongitudeInDegrees()) + "," + String.valueOf(boundingCoords[1].getLatitudeInDegrees()) + "," + String.valueOf(boundingCoords[1].getLongitudeInDegrees());
                log.info("OCID BBOX is set to: " + boundParameter + "  with radius " + radius + " Km.");
                StringBuilder sb = new StringBuilder();
                sb.append("http://www.opencellid.org/cell/getInArea?key=").append(CellTracker.OCID_API_KEY).append("&BBOX=").append(boundParameter);
                log.info("OCID MCC is set to: " + cell.getMobileCountryCode());
                if (cell.getMobileCountryCode() != Integer.MAX_VALUE) {
                    sb.append("&mcc=").append(cell.getMobileCountryCode());
                }
                log.info("OCID MNC is set to: " + cell.getMobileNetworkCode());
                if (cell.getMobileNetworkCode() != Integer.MAX_VALUE) {
                    sb.append("&mnc=").append(cell.getMobileNetworkCode());
                }
                sb.append("&format=csv");
                new RequestTask(injectionActivity, type, new RequestTask.AsyncTaskCompleteListener() {

                    @Override
                    public void onAsyncTaskSucceeded() {
                        log.verbose("RequestTask's OCID download was successful. Callback rechecking connected cell against database");
                        service.getCellTracker().compareLacAndOpenDb();
                    }

                    @Override
                    public void onAsyncTaskFailed(String result) {
                    }
                }).execute(sb.toString());
            }
        } else {
            Fragment myFragment = injectionActivity.getSupportFragmentManager().findFragmentByTag(String.valueOf(DrawerMenu.ID.MAIN.ALL_CURRENT_CELL_DETAILS));
            if (myFragment instanceof MapFragment) {
                ((MapFragment) myFragment).setRefreshActionButtonState(false);
            }
            Helpers.sendMsg(injectionActivity, injectionActivity.getString(R.string.no_opencellid_key_detected));
        }
    } else {
        Fragment myFragment = injectionActivity.getSupportFragmentManager().findFragmentByTag(String.valueOf(DrawerMenu.ID.MAIN.ALL_CURRENT_CELL_DETAILS));
        if (myFragment instanceof MapFragment) {
            ((MapFragment) myFragment).setRefreshActionButtonState(false);
        }
        final AlertDialog.Builder builder = new AlertDialog.Builder(injectionActivity);
        builder.setTitle(R.string.no_network_connection_title).setMessage(R.string.no_network_connection_message);
        builder.create().show();
    }
}
Also used : AlertDialog(android.app.AlertDialog) MapFragment(com.secupwn.aimsicd.ui.fragments.MapFragment) Fragment(android.support.v4.app.Fragment) MapFragment(com.secupwn.aimsicd.ui.fragments.MapFragment)

Example 67 with Builder

use of android.support.v4.app.NotificationCompat.Builder in project Android-IMSI-Catcher-Detector by CellularPrivacy.

the class Helpers method importCellTowersData.

/**
     * Description:      Imports cell data from the specified file
     *
     * Used:
     * @param celltowersPath path to the cell_towers.csv / cell_towers.csv.gz
     * @param cell Current Cell Information
     * @param importFile
     *
     */
public static void importCellTowersData(InjectionAppCompatActivity injectionActivity, Cell cell, Uri importFile, final AimsicdService service) {
    if (Helpers.isNetAvailable(injectionActivity)) {
        // Use a 2 Km radius with center at GPS location.
        int radius = 2;
        if (Double.doubleToRawLongBits(cell.getLat()) != 0 && Double.doubleToRawLongBits(cell.getLon()) != 0) {
            GeoLocation currentLoc = GeoLocation.fromDegrees(cell.getLat(), cell.getLon());
            log.info("OCID location: " + currentLoc.toString() + "  with radius " + radius + " Km.");
            log.info("OCID MCC is set to: " + cell.getMobileCountryCode());
            log.info("OCID MNC is set to: " + cell.getMobileNetworkCode());
            new ImportTask(injectionActivity, importFile, cell.getMobileCountryCode(), cell.getMobileNetworkCode(), currentLoc, radius, new ImportTask.AsyncTaskCompleteListener() {

                @Override
                public void onAsyncTaskSucceeded() {
                    log.verbose("ImportTask's OCID import was successful. Callback rechecking connected cell against database");
                    service.getCellTracker().compareLacAndOpenDb();
                }

                @Override
                public void onAsyncTaskFailed(String result) {
                }
            }).execute();
        }
    } else {
        Fragment myFragment = injectionActivity.getSupportFragmentManager().findFragmentByTag(String.valueOf(DrawerMenu.ID.MAIN.ALL_CURRENT_CELL_DETAILS));
        if (myFragment instanceof MapFragment) {
            ((MapFragment) myFragment).setRefreshActionButtonState(false);
        }
        final AlertDialog.Builder builder = new AlertDialog.Builder(injectionActivity);
        builder.setTitle(R.string.no_network_connection_title).setMessage(R.string.no_network_connection_message);
        builder.create().show();
    }
}
Also used : AlertDialog(android.app.AlertDialog) MapFragment(com.secupwn.aimsicd.ui.fragments.MapFragment) Fragment(android.support.v4.app.Fragment) MapFragment(com.secupwn.aimsicd.ui.fragments.MapFragment)

Example 68 with Builder

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

the class DownloadService method postAuthenticationNotification.

private void postAuthenticationNotification(final DownloadRequest downloadRequest) {
    handler.post(() -> {
        final String resourceTitle = (downloadRequest.getTitle() != null) ? downloadRequest.getTitle() : downloadRequest.getSource();
        NotificationCompat.Builder builder = new NotificationCompat.Builder(DownloadService.this);
        builder.setTicker(getText(R.string.authentication_notification_title)).setContentTitle(getText(R.string.authentication_notification_title)).setContentText(getText(R.string.authentication_notification_msg)).setStyle(new NotificationCompat.BigTextStyle().bigText(getText(R.string.authentication_notification_msg) + ": " + resourceTitle)).setSmallIcon(R.drawable.ic_stat_authentication).setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_stat_authentication)).setAutoCancel(true).setContentIntent(ClientConfig.downloadServiceCallbacks.getAuthentificationNotificationContentIntent(DownloadService.this, downloadRequest)).setVisibility(Notification.VISIBILITY_PUBLIC);
        Notification n = builder.build();
        NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        nm.notify(downloadRequest.getSource().hashCode(), n);
    });
}
Also used : NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Notification(android.app.Notification)

Example 69 with Builder

use of android.support.v4.app.NotificationCompat.Builder in project acra by ACRA.

the class ReportExecutor method createNotification.

/**
     * Creates a status bar notification.
     *
     * The action triggered when the notification is selected is to start the
     * {@link CrashReportDialog} Activity.
     *
     * @param reportFile    Report file to send.
     */
private void createNotification(@NonNull File reportFile, @NonNull ReportBuilder reportBuilder) {
    final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    // Default notification icon is the warning symbol
    final int icon = config.resNotifIcon();
    final CharSequence tickerText = context.getText(config.resNotifTickerText());
    final long when = System.currentTimeMillis();
    if (ACRA.DEV_LOGGING)
        ACRA.log.d(LOG_TAG, "Creating Notification for " + reportFile);
    final Intent crashReportDialogIntent = createCrashReportDialogIntent(reportFile, reportBuilder);
    final PendingIntent contentIntent = PendingIntent.getActivity(context, mNotificationCounter++, crashReportDialogIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    final CharSequence contentTitle = context.getText(config.resNotifTitle());
    final CharSequence contentText = context.getText(config.resNotifText());
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    final Notification notification = builder.setSmallIcon(icon).setTicker(tickerText).setWhen(when).setAutoCancel(true).setContentTitle(contentTitle).setContentText(contentText).setContentIntent(contentIntent).build();
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    // The deleteIntent is invoked when the user swipes away the Notification.
    // In this case we invoke the CrashReportDialog with EXTRA_FORCE_CANCEL==true
    // which will cause BaseCrashReportDialog to clear the crash report and finish itself.
    final Intent deleteIntent = createCrashReportDialogIntent(reportFile, reportBuilder);
    deleteIntent.putExtra(ACRAConstants.EXTRA_FORCE_CANCEL, true);
    notification.deleteIntent = PendingIntent.getActivity(context, -1, deleteIntent, 0);
    // Send new notification
    notificationManager.notify(ACRAConstants.NOTIF_CRASH_ID, notification);
}
Also used : NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Example 70 with Builder

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

the class ProxyDialog method test.

private void test() {
    if (subscription != null) {
        subscription.unsubscribe();
    }
    if (!checkValidity()) {
        setTestRequired(true);
        return;
    }
    TypedArray res = context.getTheme().obtainStyledAttributes(new int[] { android.R.attr.textColorPrimary });
    int textColorPrimary = res.getColor(0, 0);
    res.recycle();
    String checking = context.getString(R.string.proxy_checking);
    txtvMessage.setTextColor(textColorPrimary);
    txtvMessage.setText("{fa-circle-o-notch spin} " + checking);
    txtvMessage.setVisibility(View.VISIBLE);
    subscription = Observable.create(new Observable.OnSubscribe<Response>() {

        @Override
        public void call(Subscriber<? super Response> subscriber) {
            String type = (String) spType.getSelectedItem();
            String host = etHost.getText().toString();
            String port = etPort.getText().toString();
            String username = etUsername.getText().toString();
            String password = etPassword.getText().toString();
            int portValue = 8080;
            if (!TextUtils.isEmpty(port)) {
                portValue = Integer.valueOf(port);
            }
            SocketAddress address = InetSocketAddress.createUnresolved(host, portValue);
            Proxy.Type proxyType = Proxy.Type.valueOf(type.toUpperCase());
            Proxy proxy = new Proxy(proxyType, address);
            OkHttpClient.Builder builder = AntennapodHttpClient.newBuilder().connectTimeout(10, TimeUnit.SECONDS).proxy(proxy);
            builder.interceptors().clear();
            OkHttpClient client = builder.build();
            if (!TextUtils.isEmpty(username)) {
                String credentials = Credentials.basic(username, password);
                client.interceptors().add(chain -> {
                    Request request = chain.request().newBuilder().header("Proxy-Authorization", credentials).build();
                    return chain.proceed(request);
                });
            }
            Request request = new Request.Builder().url("http://www.google.com").head().build();
            try {
                Response response = client.newCall(request).execute();
                subscriber.onNext(response);
            } catch (IOException e) {
                subscriber.onError(e);
            }
            subscriber.onCompleted();
        }
    }).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(response -> {
        int colorId;
        String icon;
        String result;
        if (response.isSuccessful()) {
            colorId = R.color.download_success_green;
            icon = "{fa-check}";
            result = context.getString(R.string.proxy_test_successful);
        } else {
            colorId = R.color.download_failed_red;
            icon = "{fa-close}";
            result = context.getString(R.string.proxy_test_failed);
        }
        int color = ContextCompat.getColor(context, colorId);
        txtvMessage.setTextColor(color);
        String message = String.format("%s %s: %s", icon, result, response.message());
        txtvMessage.setText(message);
        setTestRequired(!response.isSuccessful());
    }, error -> {
        String icon = "{fa-close}";
        String result = context.getString(R.string.proxy_test_failed);
        int color = ContextCompat.getColor(context, R.color.download_failed_red);
        txtvMessage.setTextColor(color);
        String message = String.format("%s %s: %s", icon, result, error.getMessage());
        txtvMessage.setText(message);
        setTestRequired(true);
    });
}
Also used : Context(android.content.Context) SocketAddress(java.net.SocketAddress) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Dialog(android.app.Dialog) Editable(android.text.Editable) TypedArray(android.content.res.TypedArray) Observable(rx.Observable) UserPreferences(de.danoeh.antennapod.core.preferences.UserPreferences) MDButton(com.afollestad.materialdialogs.internal.MDButton) Patterns(android.util.Patterns) Proxy(java.net.Proxy) Schedulers(rx.schedulers.Schedulers) View(android.view.View) Response(okhttp3.Response) AdapterView(android.widget.AdapterView) AntennapodHttpClient(de.danoeh.antennapod.core.service.download.AntennapodHttpClient) Request(okhttp3.Request) Subscriber(rx.Subscriber) R(de.danoeh.antennapod.R) ContextCompat(android.support.v4.content.ContextCompat) TextUtils(android.text.TextUtils) DialogAction(com.afollestad.materialdialogs.DialogAction) IOException(java.io.IOException) Credentials(okhttp3.Credentials) InetSocketAddress(java.net.InetSocketAddress) ProxyConfig(de.danoeh.antennapod.core.service.download.ProxyConfig) Spinner(android.widget.Spinner) TimeUnit(java.util.concurrent.TimeUnit) ArrayAdapter(android.widget.ArrayAdapter) TextView(android.widget.TextView) OkHttpClient(okhttp3.OkHttpClient) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Subscription(rx.Subscription) EditText(android.widget.EditText) TextWatcher(android.text.TextWatcher) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) IOException(java.io.IOException) Observable(rx.Observable) Response(okhttp3.Response) Proxy(java.net.Proxy) TypedArray(android.content.res.TypedArray) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Aggregations

NotificationCompat (android.support.v4.app.NotificationCompat)105 PendingIntent (android.app.PendingIntent)86 Intent (android.content.Intent)76 NotificationManager (android.app.NotificationManager)35 Notification (android.app.Notification)29 Builder (android.support.v4.app.NotificationCompat.Builder)19 Context (android.content.Context)16 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)14 Uri (android.net.Uri)11 Bundle (android.os.Bundle)10 Bitmap (android.graphics.Bitmap)9 View (android.view.View)9 RemoteViews (android.widget.RemoteViews)9 IOException (java.io.IOException)9 AlertDialog (android.app.AlertDialog)7 DialogInterface (android.content.DialogInterface)7 Paint (android.graphics.Paint)6 SpannableString (android.text.SpannableString)6 TypedValue (android.util.TypedValue)6 TextView (android.widget.TextView)6