Android Open Source - wifi-auto-forget Connectivity Change View






From Project

Back to project page wifi-auto-forget.

License

The source code is released under:

GNU General Public License

If you think the Android project wifi-auto-forget listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.cebesius.wifiautoforget.mvp;
//  w ww  . j ava  2 s  .  c  o m
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.util.Log;
import android.widget.Toast;

import com.cebesius.wifiautoforget.R;
import com.cebesius.wifiautoforget.domain.AutoForgetWifi;
import com.cebesius.wifiautoforget.gateway.NotificationIds;
import com.cebesius.wifiautoforget.service.AddWifiService;
import com.cebesius.wifiautoforget.util.BusPortal;

import static com.cebesius.wifiautoforget.mvp.AppPresenter.*;

/**
 * Implementation of ConnectivityChangeView
 */
public class ConnectivityChangeView {

    private static final String TAG = ConnectivityChangeView.class.getSimpleName();
    private static final int REQUEST_CODE_UNKNOWN_WIFI_SINGLE_AUTOFORGET = 0;
    private static final int REQUEST_CODE_UNKNOWN_WIFI_PERMANENT_AUTOFORGET = 1;
    private static final int REQUEST_CODE_UNKNOWN_WIFI_PERMANENT_IGNORE = 2;

    private final Context context;
    private final NotificationManager notificationManager;

    public ConnectivityChangeView(Context context, NotificationManager notificationManager) {
        this.notificationManager = notificationManager;
        this.context = context;
    }

    public void showUnknownWifiNotification(AutoForgetWifi autoForgetWifi, NotificationVerbosity notificationVerbosity) {
        Notification.Builder notificationBuilder = new Notification.Builder(context)
                .setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle(context.getString(R.string.notification_unknown_wifi_title))
                .setContentText(autoForgetWifi.getSsid());

        if (notificationVerbosity == NotificationVerbosity.EXTENDED) {
            notificationBuilder.setSubText(context.getString(R.string.notification_unknown_wifi_subtext));
        }

        // Single AutoForget action
        notificationBuilder.addAction(
                android.R.drawable.ic_input_add,
                context.getString(R.string.add_single_autoforget),
                PendingIntent.getService(
                        context,
                        REQUEST_CODE_UNKNOWN_WIFI_SINGLE_AUTOFORGET,
                        AddWifiService.buildIntent(
                                context,
                                autoForgetWifi,
                                AutoForgetWifi.Behavior.SINGLE
                        ),
                        PendingIntent.FLAG_UPDATE_CURRENT
                )
        );

        // Permanent AutoForget action
        notificationBuilder.addAction(
                android.R.drawable.ic_input_add,
                context.getString(R.string.add_permanent_autoforget),
                PendingIntent.getService(
                        context,
                        REQUEST_CODE_UNKNOWN_WIFI_PERMANENT_AUTOFORGET,
                        AddWifiService.buildIntent(
                                context,
                                autoForgetWifi,
                                AutoForgetWifi.Behavior.PERMANENT
                        ),
                        PendingIntent.FLAG_UPDATE_CURRENT
                )
        );

        // Permanent Ignore action
        notificationBuilder.setDeleteIntent(
                PendingIntent.getService(
                        context,
                        REQUEST_CODE_UNKNOWN_WIFI_PERMANENT_IGNORE,
                        AddWifiService.buildIntent(
                                context,
                                autoForgetWifi,
                                AutoForgetWifi.Behavior.NEVER
                        ),
                        PendingIntent.FLAG_UPDATE_CURRENT
                )
        );

        notificationManager.notify(NotificationIds.CONNECTED_UNKNOWN_WIFI, notificationBuilder.build());
    }

    public void showPermanentAutoForgetNotification(AutoForgetWifi autoForgetWifi, NotificationVerbosity notificationVerbosity) {
        // TODO: implement showPermanentAutoForgetNotification()
        BusPortal.getInstance().post(new ShowToastEvent("TODO: show permanent AutoForget notification", Toast.LENGTH_SHORT));
        Log.v(TAG, "showPermanentAutoForgetNotification() not yet implemented");

    }

    public enum NotificationVerbosity {
        BRIEF,
        EXTENDED
    }
}




Java Source Code List

antoche.HockeySender.java
com.cebesius.wifiautoforget.Secrets.java
com.cebesius.wifiautoforget.WifiAutoForgetApplication.java
com.cebesius.wifiautoforget.activity.AutoForgetWifisActivity.java
com.cebesius.wifiautoforget.adapter.AutoForgetWifisAdapter.java
com.cebesius.wifiautoforget.dialog.ChangeAutoForgetBehaviorDialog.java
com.cebesius.wifiautoforget.domain.AutoForgetWifi.java
com.cebesius.wifiautoforget.gateway.AddWifiNotificationUsageStorage.java
com.cebesius.wifiautoforget.gateway.AutoForgetWifiStorage.java
com.cebesius.wifiautoforget.gateway.NotificationIds.java
com.cebesius.wifiautoforget.gateway.SharedPreferenceKeys.java
com.cebesius.wifiautoforget.gateway.UserPreferenceStorage.java
com.cebesius.wifiautoforget.model.AutoForgetWifiModel.java
com.cebesius.wifiautoforget.mvp.ActivityView.java
com.cebesius.wifiautoforget.mvp.AddWifiModel.java
com.cebesius.wifiautoforget.mvp.AddWifiPresenter.java
com.cebesius.wifiautoforget.mvp.AddWifiView.java
com.cebesius.wifiautoforget.mvp.AppModel.java
com.cebesius.wifiautoforget.mvp.AppPresenter.java
com.cebesius.wifiautoforget.mvp.AppView.java
com.cebesius.wifiautoforget.mvp.AutoForgetWifisModel.java
com.cebesius.wifiautoforget.mvp.AutoForgetWifisPresenter.java
com.cebesius.wifiautoforget.mvp.AutoForgetWifisView.java
com.cebesius.wifiautoforget.mvp.ConnectivityChangeModel.java
com.cebesius.wifiautoforget.mvp.ConnectivityChangePresenter.java
com.cebesius.wifiautoforget.mvp.ConnectivityChangeView.java
com.cebesius.wifiautoforget.receiver.ConnectivityChangeReceiver.java
com.cebesius.wifiautoforget.service.AddWifiService.java
com.cebesius.wifiautoforget.service.ConnectivityChangeService.java
com.cebesius.wifiautoforget.util.AutoForgetDelegate.java
com.cebesius.wifiautoforget.util.BusPortal.java
com.cebesius.wifiautoforget.widget.AutoForgetWifiItem.java