Example usage for android.widget RemoteViews reapply

List of usage examples for android.widget RemoteViews reapply

Introduction

In this page you can find the example usage for android.widget RemoteViews reapply.

Prototype

public void reapply(Context context, View v) 

Source Link

Document

Applies all of the actions to the provided view.

Usage

From source file:me.spadival.podmode.PodNotifyService.java

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {

    String notifyPackage = (String) event.getPackageName();

    if (!event.getClassName().equals(NOTIFICATION_CLASS))
        return;//from   w  w w  .  j a v  a 2  s  . c o m

    if (notifyPackage.equals(SYSTEMUI_PACKAGE) || notifyPackage.equals(THIS_PACKAGE)
            || notifyPackage.equals(ANDROID_PACKAGE))
        return;

    PackageManager pm = getPackageManager();

    String notifyAppName = null;

    try {
        notifyAppName = (String) pm.getApplicationLabel(pm.getApplicationInfo(notifyPackage, 0));
    } catch (NameNotFoundException e1) {
        e1.printStackTrace();
    }

    if (notifyAppName == null)
        return;

    if (notifyPackage.equals(GMAPS_PACKAGE))
        notifyAppName = getString(R.string.nav_appname);

    if (notifyPackage.equals(GNOW_PACKAGE))
        notifyAppName = "Google Now";

    List<CharSequence> textList = event.getText();

    String notifyText = "";

    if (textList.size() > 0)
        notifyText = textList.get(0).toString();

    if (notifyText.equals("") || notifyPackage.equals(GMAIL_PACKAGE)) {
        Notification eventNotification = (Notification) event.getParcelableData();

        RemoteViews notifyView = eventNotification.contentView;
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        ViewGroup localView = null;
        try {
            localView = (ViewGroup) inflater.inflate(notifyView.getLayoutId(), null);
        } catch (Exception e) {
            //      e.printStackTrace();
            return;
        }

        try {

            notifyView.reapply(getApplicationContext(), localView);
        } catch (NotFoundException e) {
            //         e.printStackTrace();
        }

        View tv = localView.findViewById(android.R.id.title);
        if (tv != null && tv instanceof TextView) {
            if (notifyPackage.equals(GNOW_PACKAGE) || notifyPackage.equals(PANDORA_PACKAGE))
                notifyText = ((TextView) tv).getText().toString();
            else
                notifyAppName += ": " + ((TextView) tv).getText().toString();
        }

        if (!notifyPackage.equals(GNOW_PACKAGE)) {

            tv = localView.findViewById(16908358);
            if (tv != null && tv instanceof TextView)
                if (notifyPackage.equals(PANDORA_PACKAGE))
                    notifyAppName += ": " + ((TextView) tv).getText().toString();
                else
                    notifyText = (String) ((TextView) tv).getText().toString();
        }

        if (notifyPackage.equals(GMAIL_PACKAGE)) {
            tv = localView.findViewById(android.R.id.text2);
            if (tv != null && tv instanceof TextView)
                notifyText = (String) ((TextView) tv).getText().toString();
        }
    }

    Intent localIntent = new Intent(PodModeService.NOTIFYACTION);
    localIntent.putExtra("package", notifyPackage);
    localIntent.putExtra("appname", notifyAppName);
    localIntent.putExtra("text", notifyText);

    LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);

}

From source file:com.dattasmoon.pebble.plugin.NotificationService.java

private String getExtraData(Notification notification, String existing_text) {
    if (Constants.IS_LOGGABLE) {
        Log.i(Constants.LOG_TAG, "I am running extra data");
    }/*from  ww  w.j  a  v  a 2 s.co m*/
    RemoteViews views = notification.contentView;
    if (views == null) {
        if (Constants.IS_LOGGABLE) {
            Log.i(Constants.LOG_TAG, "ContentView was empty, returning a blank string");
        }
        return "";
    }

    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    try {
        ViewGroup localView = (ViewGroup) inflater.inflate(views.getLayoutId(), null);
        views.reapply(getApplicationContext(), localView);
        return dumpViewGroup(0, localView, existing_text);
    } catch (android.content.res.Resources.NotFoundException e) {
        return "";
    } catch (RemoteViews.ActionException e) {
        return "";
    }
}

From source file:com.dattasmoon.pebble.plugin.NotificationService.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private String getExtraBigData(Notification notification, String existing_text) {
    if (Constants.IS_LOGGABLE) {
        Log.i(Constants.LOG_TAG, "I am running extra big data");
    }/*  w  w  w.  j a  v  a  2s  .  c om*/
    RemoteViews views = null;
    try {
        views = notification.bigContentView;
    } catch (NoSuchFieldError e) {
        return getExtraData(notification, existing_text);
    }
    if (views == null) {
        if (Constants.IS_LOGGABLE) {
            Log.i(Constants.LOG_TAG, "bigContentView was empty, running normal");
        }
        return getExtraData(notification, existing_text);
    }
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    try {
        ViewGroup localView = (ViewGroup) inflater.inflate(views.getLayoutId(), null);
        views.reapply(getApplicationContext(), localView);
        return dumpViewGroup(0, localView, existing_text);
    } catch (android.content.res.Resources.NotFoundException e) {
        return "";
    }
}