Example usage for android.content Intent setPackage

List of usage examples for android.content Intent setPackage

Introduction

In this page you can find the example usage for android.content Intent setPackage.

Prototype

public @NonNull Intent setPackage(@Nullable String packageName) 

Source Link

Document

(Usually optional) Set an explicit application package name that limits the components this Intent will resolve to.

Usage

From source file:org.getlantern.firetweet.fragment.support.StatusFragment.java

@Override
public void onStatusActionClick(StatusViewHolder holder, int id, int position) {
    final ParcelableStatus status = mStatusAdapter.getStatus(position);
    if (status == null)
        return;//  w  w w.j  a  v  a 2s .c  o  m
    switch (id) {
    case R.id.reply_count: {
        final Context context = getActivity();
        final Intent intent = new Intent(IntentConstants.INTENT_ACTION_REPLY);
        intent.setPackage(context.getPackageName());
        intent.putExtra(IntentConstants.EXTRA_STATUS, status);
        context.startActivity(intent);
        break;
    }
    case R.id.retweet_count: {
        RetweetQuoteDialogFragment.show(getFragmentManager(), status);
        break;
    }
    case R.id.favorite_count: {
        final AsyncTwitterWrapper twitter = getTwitterWrapper();
        if (twitter == null)
            return;
        if (status.is_favorite) {
            twitter.destroyFavoriteAsync(status.account_id, status.id);
        } else {
            twitter.createFavoriteAsync(status.account_id, status.id);
        }
        break;
    }
    }
}

From source file:com.example.qrcode.BarcodeScanner.java

/**
 * Starts an intent to scan and decode a barcode.
 *///ww w.  j  av  a 2 s .  c  o m
public void scan(JSONArray args) {
    Intent intentScan = new Intent(SCAN_INTENT);
    intentScan.addCategory(Intent.CATEGORY_DEFAULT);

    // add config as intent extras
    if (args.length() > 0) {

        JSONObject obj;
        JSONArray names;
        String key;
        Object value;

        for (int i = 0; i < args.length(); i++) {

            try {
                obj = args.getJSONObject(i);
            } catch (JSONException e) {
                Log.i("CordovaLog", e.getLocalizedMessage());
                continue;
            }

            names = obj.names();
            for (int j = 0; j < names.length(); j++) {
                try {
                    key = names.getString(j);
                    value = obj.get(key);

                    if (value instanceof Integer) {
                        intentScan.putExtra(key, (Integer) value);
                    } else if (value instanceof String) {
                        intentScan.putExtra(key, (String) value);
                    }

                } catch (JSONException e) {
                    Log.i("CordovaLog", e.getLocalizedMessage());
                    continue;
                }
            }
        }

    }

    // avoid calling other phonegap apps
    intentScan.setPackage(this.cordova.getActivity().getApplicationContext().getPackageName());

    this.cordova.startActivityForResult((CordovaPlugin) this, intentScan, REQUEST_CODE);
}

From source file:com.partypoker.poker.engagement.reach.EngagementDefaultNotifier.java

@Override
public void executeNotifAnnouncementAction(EngagementNotifAnnouncement notifAnnouncement) {
    /* Launch action intent (view activity in its own task) */
    try {/*from ww  w.  j  a  va  2 s  . c  o  m*/
        Intent intent = Intent.parseUri(notifAnnouncement.getActionURL(), 0);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        doExecuteNotifAnnouncementAction(notifAnnouncement, intent);
    } catch (Exception e) {
        /*
         * Invalid/Missing Action URL: launch/resume application instead if system notification and no
         * session.
         */
        if (notifAnnouncement.isSystemNotification()
                && EngagementActivityManager.getInstance().getCurrentActivityAlias() == null) {
            PackageManager packageManager = mContext.getPackageManager();
            Intent intent = packageManager.getLaunchIntentForPackage(mContext.getPackageName());
            if (intent != null) {
                /*
                 * Set package null is the magic enabling the same behavior than launching from Home
                 * Screen, e.g. perfect resume of the task. No idea why the setPackage messes the intent
                 * up...
                 */
                if (intent.getComponent() != null)
                    intent.setPackage(null);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                doExecuteNotifAnnouncementAction(notifAnnouncement, intent);
            }
        }
    }
}

From source file:com.ubikod.capptain.android.sdk.reach.CapptainDefaultNotifier.java

@Override
public void executeNotifAnnouncementAction(CapptainNotifAnnouncement notifAnnouncement) {
    /* Launch action intent (view activity in its own task) */
    try {/*  w w w . j  av a  2 s  .  c o  m*/
        Intent intent = Intent.parseUri(notifAnnouncement.getActionURL(), 0);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        doExecuteNotifAnnouncementAction(notifAnnouncement, intent);
    } catch (Exception e) {
        /*
         * Invalid/Missing Action URL: launch/resume application instead if system notification and no
         * session.
         */
        if (notifAnnouncement.isSystemNotification()
                && CapptainActivityManager.getInstance().getCurrentActivityAlias() == null) {
            PackageManager packageManager = mContext.getPackageManager();
            Intent intent = packageManager.getLaunchIntentForPackage(mContext.getPackageName());
            if (intent != null) {
                /*
                 * Set package null is the magic enabling the same behavior than launching from Home
                 * Screen, e.g. perfect resume of the task. No idea why the setPackage messes the intent
                 * up...
                 */
                if (intent.getComponent() != null)
                    intent.setPackage(null);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                doExecuteNotifAnnouncementAction(notifAnnouncement, intent);
            }
        }
    }
}

From source file:com.tct.mail.utils.NotificationUtils.java

/**
 * Validate the notifications notification.
 *//*from www .j  a  v a2  s .  com*/
private static void validateNotifications(Context context, final Folder folder, final Account account,
        boolean getAttention, boolean ignoreUnobtrusiveSetting, NotificationKey key,
        final ContactPhotoFetcher photoFetcher) {

    NotificationManagerCompat nm = NotificationManagerCompat.from(context);

    final NotificationMap notificationMap = getNotificationMap(context);
    if (LogUtils.isLoggable(LOG_TAG, LogUtils.VERBOSE)) {
        LogUtils.i(LOG_TAG,
                "Validating Notification: %s mapSize: %d "
                        + "folder: %s getAttention: %b ignoreUnobtrusive: %b",
                createNotificationString(notificationMap), notificationMap.size(), folder.name, getAttention,
                ignoreUnobtrusiveSetting);
    } else {
        LogUtils.i(LOG_TAG, "Validating Notification, mapSize: %d " + "getAttention: %b ignoreUnobtrusive: %b",
                notificationMap.size(), getAttention, ignoreUnobtrusiveSetting);
    }
    // The number of unread messages for this account and label.
    final Integer unread = notificationMap.getUnread(key);
    final int unreadCount = unread != null ? unread.intValue() : 0;
    final Integer unseen = notificationMap.getUnseen(key);
    int unseenCount = unseen != null ? unseen.intValue() : 0;

    Cursor cursor = null;

    try {
        final Uri.Builder uriBuilder = folder.conversationListUri.buildUpon();
        uriBuilder.appendQueryParameter(UIProvider.SEEN_QUERY_PARAMETER, Boolean.FALSE.toString());
        // Do not allow this quick check to disrupt any active network-enabled conversation
        // cursor.
        uriBuilder.appendQueryParameter(UIProvider.ConversationListQueryParameters.USE_NETWORK,
                Boolean.FALSE.toString());
        cursor = context.getContentResolver().query(uriBuilder.build(), UIProvider.CONVERSATION_PROJECTION,
                null, null, null);
        if (cursor == null) {
            // This folder doesn't exist.
            LogUtils.i(LOG_TAG, "The cursor is null, so the specified folder probably does not exist");
            clearFolderNotification(context, account, folder, false);
            return;
        }
        final int cursorUnseenCount = cursor.getCount();

        // Make sure the unseen count matches the number of items in the cursor.  But, we don't
        // want to overwrite a 0 unseen count that was specified in the intent
        if (unseenCount != 0 && unseenCount != cursorUnseenCount) {
            LogUtils.i(LOG_TAG, "Unseen count doesn't match cursor count.  unseen: %d cursor count: %d",
                    unseenCount, cursorUnseenCount);
            unseenCount = cursorUnseenCount;
        }

        // For the purpose of the notifications, the unseen count should be capped at the num of
        // unread conversations.
        if (unseenCount > unreadCount) {
            unseenCount = unreadCount;
        }

        final int notificationId = getNotificationId(account.getAccountManagerAccount(), folder);

        NotificationKey notificationKey = new NotificationKey(account, folder);

        if (unseenCount == 0) {
            LogUtils.i(LOG_TAG, "validateNotifications - cancelling account %s / folder %s",
                    LogUtils.sanitizeName(LOG_TAG, account.getEmailAddress()),
                    LogUtils.sanitizeName(LOG_TAG, folder.persistentId));
            //TS: Gantao 2015-08-25 EMAIL BUGFIX_1073998 MOD_S
            //May happen SecurityException while cancle notification,only catch it.
            try {
                nm.cancel(notificationId);
            } catch (SecurityException se) {
                LogUtils.e(LOG_TAG, "Can not find the pacakage while cancle the notification: %d",
                        notificationId);
            }
            //TS: Gantao 2015-08-25 EMAIL BUGFIX_1073998 MOD_E
            cancelConversationNotifications(notificationKey, nm);

            return;
        }

        // We now have all we need to create the notification and the pending intent
        PendingIntent clickIntent = null;

        NotificationCompat.Builder notification = new NotificationCompat.Builder(context);
        NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender();
        Map<Integer, NotificationBuilders> msgNotifications = new ArrayMap<Integer, NotificationBuilders>();

        if (com.tct.mail.utils.Utils.isRunningLOrLater()) {
            notification.setColor(context.getResources().getColor(R.color.notification_icon_mail_orange));
        }
        // TODO(shahrk) - fix for multiple mail
        // if(folder.notificationIconResId != 0 || unseenCount <=  2)
        notification.setSmallIcon(R.drawable.ic_notification_mail_24dp);
        notification.setTicker(account.getDisplayName());
        notification.setVisibility(NotificationCompat.VISIBILITY_PRIVATE);

        final long when;

        final long oldWhen = NotificationActionUtils.sNotificationTimestamps.get(notificationId);
        if (oldWhen != 0) {
            when = oldWhen;
        } else {
            when = System.currentTimeMillis();
        }

        notification.setWhen(when);

        // The timestamp is now stored in the notification, so we can remove it from here
        NotificationActionUtils.sNotificationTimestamps.delete(notificationId);

        // Dispatch a CLEAR_NEW_MAIL_NOTIFICATIONS intent if the user taps the "X" next to a
        // notification.  Also this intent gets fired when the user taps on a notification as
        // the AutoCancel flag has been set
        final Intent cancelNotificationIntent = new Intent(
                MailIntentService.ACTION_CLEAR_NEW_MAIL_NOTIFICATIONS);
        cancelNotificationIntent.setPackage(context.getPackageName());
        cancelNotificationIntent.setData(Utils.appendVersionQueryParameter(context, folder.folderUri.fullUri));
        cancelNotificationIntent.putExtra(Utils.EXTRA_ACCOUNT, account);
        cancelNotificationIntent.putExtra(Utils.EXTRA_FOLDER, folder);

        notification.setDeleteIntent(
                PendingIntent.getService(context, notificationId, cancelNotificationIntent, 0));

        // Ensure that the notification is cleared when the user selects it
        notification.setAutoCancel(true);

        boolean eventInfoConfigured = false;

        final boolean isInbox = folder.folderUri.equals(account.settings.defaultInbox);
        final FolderPreferences folderPreferences = new FolderPreferences(context, account.getAccountId(),
                folder, isInbox);

        if (isInbox) {
            final AccountPreferences accountPreferences = new AccountPreferences(context,
                    account.getAccountId());
            moveNotificationSetting(accountPreferences, folderPreferences);
        }

        if (!folderPreferences.areNotificationsEnabled()) {
            LogUtils.i(LOG_TAG, "Notifications are disabled for this folder; not notifying");
            // Don't notify
            return;
        }

        if (unreadCount > 0) {
            // How can I order this properly?
            if (cursor.moveToNext()) {
                final Intent notificationIntent;

                // Launch directly to the conversation, if there is only 1 unseen conversation
                final boolean launchConversationMode = (unseenCount == 1);
                if (launchConversationMode) {
                    notificationIntent = createViewConversationIntent(context, account, folder, cursor);
                } else {
                    notificationIntent = createViewConversationIntent(context, account, folder, null);
                }

                Analytics.getInstance().sendEvent("notification_create",
                        launchConversationMode ? "conversation" : "conversation_list",
                        folder.getTypeDescription(), unseenCount);

                if (notificationIntent == null) {
                    LogUtils.e(LOG_TAG, "Null intent when building notification");
                    return;
                }

                clickIntent = createClickPendingIntent(context, notificationIntent);

                configureLatestEventInfoFromConversation(context, account, folderPreferences, notification,
                        wearableExtender, msgNotifications, notificationId, cursor, clickIntent,
                        notificationIntent, unreadCount, unseenCount, folder, when, photoFetcher);
                eventInfoConfigured = true;
            }
        }

        final boolean vibrate = folderPreferences.isNotificationVibrateEnabled();
        final String ringtoneUri = folderPreferences.getNotificationRingtoneUri();
        //TS: junwei-xu 2015-2-12 EMAIL BUGFIX_884937 MOD_S
        //final boolean notifyOnce = !folderPreferences.isEveryMessageNotificationEnabled();

        //if (!ignoreUnobtrusiveSetting && notifyOnce) {
        //    // If the user has "unobtrusive notifications" enabled, only alert the first time
        //    // new mail is received in this account.  This is the default behavior.  See
        //    // bugs 2412348 and 2413490.
        //    LogUtils.d(LOG_TAG, "Setting Alert Once");
        //    notification.setOnlyAlertOnce(true);
        //}
        //TS: junwei-xu 2015-2-12 EMAIL BUGFIX_884937 MOD_E

        LogUtils.i(LOG_TAG, "Account: %s vibrate: %s",
                LogUtils.sanitizeName(LOG_TAG, account.getEmailAddress()),
                Boolean.toString(folderPreferences.isNotificationVibrateEnabled()));

        int defaults = 0;

        // Check if any current conversation notifications exist previously.  Only notify if
        // one of them is new.
        boolean hasNewConversationNotification;
        Set<Integer> prevConversationNotifications = sConversationNotificationMap.get(notificationKey);
        if (prevConversationNotifications != null) {
            hasNewConversationNotification = false;
            for (Integer currentNotificationId : msgNotifications.keySet()) {
                if (!prevConversationNotifications.contains(currentNotificationId)) {
                    hasNewConversationNotification = true;
                    break;
                }
            }
        } else {
            hasNewConversationNotification = true;
        }

        //TS:zheng.zou 2015-12-17 EMAIL BUGFIX_861247  ADD_S
        final int lastUnreadCount = sLastNotificationUnreadCount.get(notificationId);
        final int lastUnseenCount = sLastNotificationUnseenCount.get(notificationId);
        final long lastWhen = sLastNotificationTimestamps.get(notificationId);
        boolean suppressSound = when - lastWhen < sMinDisturbTimeGap;
        if (lastUnreadCount == unreadCount && lastUnseenCount == unseenCount && suppressSound) {
            LogUtils.i(LOG_TAG, "same with unseen count and unread count, return");
            return;
        }
        LogUtils.i(LOG_TAG, "suppressSound = " + suppressSound);
        //TS:zheng.zou 2015-12-17 EMAIL BUGFIX_861247  ADD_E
        LogUtils.d(LOG_TAG, "getAttention=%s,oldWhen=%s,hasNewConversationNotification=%s", getAttention,
                oldWhen, hasNewConversationNotification);

        /*
         * We do not want to notify if this is coming back from an Undo notification, hence the
         * oldWhen check.
         */
        if (getAttention && oldWhen == 0 && hasNewConversationNotification && !suppressSound) { //TS:zheng.zou 2015-12-17 EMAIL BUGFIX_861247  MOD
            final AccountPreferences accountPreferences = new AccountPreferences(context,
                    account.getAccountId());
            if (accountPreferences.areNotificationsEnabled()) {
                if (vibrate) {
                    defaults |= Notification.DEFAULT_VIBRATE;
                }

                notification.setSound(TextUtils.isEmpty(ringtoneUri) ? null : Uri.parse(ringtoneUri));
                LogUtils.i(LOG_TAG, "New email in %s vibrateWhen: %s, playing notification: %s",
                        LogUtils.sanitizeName(LOG_TAG, account.getEmailAddress()), vibrate, ringtoneUri);
                sLastNotificationTimestamps.put(notificationId, when); //TS:zheng.zou 2015-12-17 EMAIL BUGFIX_861247  ADD
            }
        }

        // TODO(skennedy) Why do we do any of the above if we're just going to bail here?
        if (eventInfoConfigured) {
            // TS: zheng.zou 2015-09-10 EMAIL BUGFIX-557052 MOD_S
            // TS: Gantao 2015-09-10 EMAIL BUGFIX-625126 MOD_S
            defaults |= Notification.DEFAULT_LIGHTS;
            //                defaults |= Notification.FLAG_SHOW_LIGHTS;
            // TS: Gantao 2015-09-10 EMAIL BUGFIX-625126 MOD_E
            notification.setDefaults(defaults);
            notification.setLights(0xff00ff00, 280, 2080);
            // TS: zheng.zou 2015-09-10 EMAIL BUGFIX-557052 MOD_E

            if (oldWhen != 0) {
                // We do not want to display the ticker again if we are re-displaying this
                // notification (like from an Undo notification)
                notification.setTicker(null);
            }

            notification.extend(wearableExtender);

            // create the *public* form of the *private* notification we have been assembling
            // TS: xiaolin.li 2014-01-23 EMAIL BUGFIX-900921 ADD_S
            /*final Notification publicNotification = createPublicNotification(context, account,
                folder, when, unseenCount, unreadCount, clickIntent);
            notification.setPublicVersion(publicNotification);*/
            try {
                final Notification publicNotification = createPublicNotification(context, account, folder, when,
                        unseenCount, unreadCount, clickIntent);
                notification.setPublicVersion(publicNotification);
            } catch (Exception e) {
                LogUtils.i(LOG_TAG, "createPublicNotification Exception.");
            }
            // TS: xiaolin.li 2014-01-23 EMAIL BUGFIX-900921 ADD_E
            LogUtils.i(LOG_TAG, " --- notify notification notificationId = " + notificationId); //TS: zheng.zolu 2015-11-09 EMAIL LOG-839780 ADD
            nm.notify(notificationId, notification.build());

            //[BUGFIX]-Add-BEGINbySCDTABLET.yafang.wei,09/06/2016,2848903,
            // SetscreenonwhencomesnewEmail
            Boolean def_is_wakeup_when_receive_email = context.getResources()
                    .getBoolean(R.bool.def_is_wakeup_when_receive_email);
            if (def_is_wakeup_when_receive_email) {
                PowerManager powerManager = (PowerManager) (context.getSystemService(Context.POWER_SERVICE));
                PowerManager.WakeLock wakeLock = null;
                wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK
                        | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
                        "Email_wake_lock");
                long wakeUpTime = 0;
                try {
                    ContentResolver cr = context.getContentResolver();
                    wakeUpTime = android.provider.Settings.System.getInt(cr,
                            Settings.System.SCREEN_OFF_TIMEOUT);
                } catch (Settings.SettingNotFoundException e) {
                }
                wakeLock.acquire(wakeUpTime);
            }
            //[BUGFIX]-Add-ENDbySCDTABLET.yafang.wei

            //TS:zheng.zou 2015-12-17 EMAIL BUGFIX_861247  ADD_S
            sLastNotificationUnreadCount.put(notificationId, unreadCount);
            sLastNotificationUnseenCount.put(notificationId, unseenCount);
            //TS:zheng.zou 2015-12-17 EMAIL BUGFIX_861247  ADD_E

            if (prevConversationNotifications != null) {
                Set<Integer> currentNotificationIds = msgNotifications.keySet();
                for (Integer prevConversationNotificationId : prevConversationNotifications) {
                    if (!currentNotificationIds.contains(prevConversationNotificationId)) {
                        nm.cancel(prevConversationNotificationId);
                        LogUtils.d(LOG_TAG, "canceling conversation notification %s",
                                prevConversationNotificationId);
                    }
                }
            }

            // TS: junwei-xu 2015-03-24 EMAIL BUGFIX-957471, ADD_S
            try {
                for (Map.Entry<Integer, NotificationBuilders> entry : msgNotifications.entrySet()) {
                    NotificationBuilders builders = entry.getValue();
                    builders.notifBuilder.extend(builders.wearableNotifBuilder);
                    nm.notify(entry.getKey(), builders.notifBuilder.build());
                    LogUtils.i(LOG_TAG, "notifying conversation notification %s", entry.getKey());// TS: zheng.zolu 2015-11-09 EMAIL LOG-839780 MOD
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            // TS: junwei-xu 2015-03-24 EMAIL BUGFIX-957471, ADD_E

            Set<Integer> conversationNotificationIds = new HashSet<Integer>();
            conversationNotificationIds.addAll(msgNotifications.keySet());
            sConversationNotificationMap.put(notificationKey, conversationNotificationIds);
        } else {
            LogUtils.i(LOG_TAG, "event info not configured - not notifying");
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

From source file:com.olacabs.customer.ui.TrackRideActivity.java

public void onClick(View view) {
    Intent intent;//  ww w.j  a  v  a 2 s  . c  o m
    switch (view.getId()) {
    case R.id.backImageView:
        onBackPressed();
    case R.id.cancelRideText:
        if (Utils.m14909a(getApplicationContext())) {
            m13979b();
            if (this.f10204k != null) {
                m13937d(this.f10204k.getCategory_id());
                this.f10219z.setEnabled(false);
                m13980b(this.f10204k.getCategory_id());
                return;
            }
            return;
        }
        m13977a();
        m13919a(Constants.CONNECTION_TIME_OUT_HEADER, Constants.NO_NETWORK_TEXT);
    case R.id.callText:
        Localytics.tagEvent("Driver Called");
        if (this.f10204k != null) {
            startActivity(new Intent("android.intent.action.CALL",
                    Uri.parse("tel:" + this.f10204k.getDriverMobile())));
        }
    case R.id.shareText:
        String str = Trace.NULL;
        if (this.f10203j != null) {
            str = this.f10203j.getShareRideText();
        }
        m13947h();
        try {
            if (VERSION.SDK_INT >= 19) {
                String defaultSmsPackage = Sms.getDefaultSmsPackage(this);
                Intent intent2 = new Intent("android.intent.action.SEND");
                intent2.setType(HTTP.PLAIN_TEXT_TYPE);
                intent2.putExtra("android.intent.extra.TEXT", str);
                if (defaultSmsPackage != null) {
                    intent2.setPackage(defaultSmsPackage);
                }
                startActivity(intent2);
                return;
            }
            intent = new Intent("android.intent.action.VIEW");
            intent.setData(Uri.parse("sms:"));
            intent.putExtra("sms_body", str);
            startActivity(intent);
        } catch (ActivityNotFoundException e) {
            OLog.m13313b("SMS app not found", new Object[0]);
        }
    case R.id.currentPositionImage:
        if (this.f10202i.m13399e() && this.f10204k != null) {
            this.f10202i.m13394a(new LatLng(this.f10204k.getLat(), this.f10204k.getLng()), true, 17);
        }
    case R.id.cusomMessageLayout:
        if ((!this.f10189R && !this.f10190S) || this.f10184M) {
            m13945g();
            f10169b = true;
            m13956m();
        }
    case R.id.rateStar:
        if (this.f10205l == 2 || this.f10205l == 3) {
            this.f10173B.setBackgroundColor(getResources().getColor(R.color.ola_black_semi_transparency));
            this.f10215v.findViewById(R.id.no_location_pointer).setVisibility(8);
            this.f10215v.findViewById(R.id.no_location_alert).setVisibility(8);
            this.f10215v.findViewById(R.id.rating_star_inactive).setVisibility(0);
            ((TextView) this.f10215v.findViewById(R.id.no_location_text))
                    .setText(R.string.track_ride_overlay_message);
            ((TextView) this.f10215v.findViewById(R.id.no_location_message))
                    .setText(R.string.track_ride_overlay_tap_message);
            this.f10215v.findViewById(R.id.rating_star_pointer).setVisibility(0);
            this.f10215v.setVisibility(0);
            m13932c("Before start trip");
            return;
        }
        intent = new Intent(this, RateRideActivity.class);
        intent.putExtra(Constants.DRIVER_IMAGE_URL,
                Sherlock.m13349d(this.f10204k != null ? this.f10204k.getDriverImageUrl() : Trace.NULL));
        intent.putExtra(Constants.ARG_BOOKING_ID, Sherlock.m13349d(this.f10203j.getBookingId()));
        if ("local_taxi".equalsIgnoreCase(this.f10204k.getCategory_id())
                || "local_auto".equalsIgnoreCase(this.f10204k.getCategory_id())) {
            intent.putExtra(Constants.ARG_CAR_CATEGORY_ID, "auto");
        } else {
            intent.putExtra(Constants.ARG_CAR_CATEGORY_ID, "cab");
        }
        startActivity(intent);
        overridePendingTransition(R.anim.slideup, R.anim.noanimation);
        m13932c("After start trip");
    case R.id.sos_image:
        m13961o();
    case R.id.view_no_location_overlay:
        this.f10215v.setVisibility(8);
        this.f10173B.setBackgroundColor(getResources().getColor(R.color.transparent));
    default:
    }
}

From source file:dev.dworks.apps.anexplorer.DocumentsActivity.java

@Override
public void onCreate(Bundle icicle) {
    if (SettingsActivity.getTranslucentMode(this) && Utils.hasKitKat()) {
        setTheme(R.style.Theme_Translucent);
    }/*from  ww w .j  av  a 2  s. c om*/
    super.onCreate(icicle);

    mRoots = DocumentsApplication.getRootsCache(this);

    setResult(Activity.RESULT_CANCELED);
    setContentView(R.layout.activity);

    final Resources res = getResources();
    mShowAsDialog = res.getBoolean(R.bool.show_as_dialog);

    if (mShowAsDialog) {
        // backgroundDimAmount from theme isn't applied; do it manually
        final WindowManager.LayoutParams a = getWindow().getAttributes();
        a.dimAmount = 0.6f;
        getWindow().setAttributes(a);

        getWindow().setFlags(0, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
        getWindow().setFlags(~0, WindowManager.LayoutParams.FLAG_DIM_BEHIND);

        // Inset ourselves to look like a dialog
        final Point size = new Point();
        getWindowManager().getDefaultDisplay().getSize(size);

        final int width = (int) res.getFraction(R.dimen.dialog_width, size.x, size.x);
        final int height = (int) res.getFraction(R.dimen.dialog_height, size.y, size.y);
        final int insetX = (size.x - width) / 2;
        final int insetY = (size.y - height) / 2;

        final Drawable before = getWindow().getDecorView().getBackground();
        final Drawable after = new InsetDrawable(before, insetX, insetY, insetX, insetY);
        ViewCompat.setBackground(getWindow().getDecorView(), after);

        // Dismiss when touch down in the dimmed inset area
        getWindow().getDecorView().setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    final float x = event.getX();
                    final float y = event.getY();
                    if (x < insetX || x > v.getWidth() - insetX || y < insetY || y > v.getHeight() - insetY) {
                        finish();
                        return true;
                    }
                }
                return false;
            }
        });

    } else {
        // Non-dialog means we have a drawer
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer_glyph,
                R.string.drawer_open, R.string.drawer_close);

        mDrawerLayout.setDrawerListener(mDrawerListener);
        mDrawerLayout.setDrawerShadow(R.drawable.ic_drawer_shadow, GravityCompat.START);
        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.RIGHT);

        mRootsContainer = findViewById(R.id.container_roots);
    }

    mDirectoryContainer = (DirectoryContainerView) findViewById(R.id.container_directory);
    mSaveContainer = (FrameLayout) findViewById(R.id.container_save);

    if (icicle != null) {
        mState = icicle.getParcelable(EXTRA_STATE);
        authenticated = icicle.getBoolean(EXTRA_AUTHENTICATED);
    } else {
        buildDefaultState();
    }

    initProtection();

    // Hide roots when we're managing a specific root
    if (mState.action == ACTION_MANAGE) {
        if (mShowAsDialog) {
            findViewById(R.id.dialog_roots).setVisibility(View.GONE);
        } else {
            mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
        }
    }

    if (mState.action == ACTION_CREATE) {
        final String mimeType = getIntent().getType();
        final String title = getIntent().getStringExtra(Intent.EXTRA_TITLE);
        SaveFragment.show(getFragmentManager(), mimeType, title);
    }

    if (mState.action == ACTION_BROWSE) {
        final Intent moreApps = new Intent(getIntent());
        moreApps.setComponent(null);
        moreApps.setPackage(null);
        RootsFragment.show(getFragmentManager(), null);
    } else if (mState.action == ACTION_OPEN || mState.action == ACTION_CREATE
            || mState.action == ACTION_GET_CONTENT) {
        RootsFragment.show(getFragmentManager(), new Intent());
    }

    if (!mState.restored) {
        if (mState.action == ACTION_MANAGE) {
            final Uri rootUri = getIntent().getData();
            new RestoreRootTask(rootUri).executeOnExecutor(getCurrentExecutor());
        } else {
            new RestoreStackTask().execute();
        }
    } else {
        onCurrentDirectoryChanged(ANIM_NONE);
    }

    if (Utils.hasKitKat()) {
        if (SettingsActivity.getTranslucentMode(this)) {
            SystemBarTintManager.setupTint(this);
            SystemBarTintManager.setNavigationInsets(this, mSaveContainer);
            mDirectoryContainer
                    .setLayoutParams(SystemBarTintManager.getToggleParams(false, R.id.container_save));
        } else {
            mDirectoryContainer
                    .setLayoutParams(SystemBarTintManager.getToggleParams(true, R.id.container_save));
        }
    }
}

From source file:activities.PaintActivity.java

private void invokeApplication(String packageName, Resources resources) {

    int requestCode = 0;
    Log.d("DialogShare", "Seleccionado ... " + packageName);
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.setType("image/*");

    shareIntent.setPackage(packageName);

    //Image/*from w ww  .ja va 2 s  . c o  m*/
    Bitmap bitmap = painter.getImageBitmap();

    if ((uriTempImage = PaintUtility.saveTempPhoto(this, bitmap)) == null)
        Toast.makeText(this, "Error al crear imagonen ", Toast.LENGTH_SHORT).show();

    shareIntent.putExtra(Intent.EXTRA_STREAM, uriTempImage);

    if (packageName.contains("twitter")) {
        shareIntent.putExtra(Intent.EXTRA_TEXT, resources.getString(string.sharecontent_twitter_text));
        requestCode = RS_CODE_SHARE_TWITTER;

    } else if (packageName.contains("facebook")) {
        // Warning: Facebook IGNORES our text. They say "These fields are intended for users to express themselves. Pre-filling these fields erodes the authenticity of the user voice."
        // One workaround is to use the Facebook SDK to post, but that doesn't allow the user to choose how they want to share. We can also make a custom landing page, and the link
        // will show the <meta content ="..."> text from that page with our link in Facebook.
        shareIntent.putExtra(Intent.EXTRA_TEXT, resources.getString(string.sharecontent_fb_text));
        requestCode = RS_CODE_SHARE_FB;
    } else if (packageName.contains("gm")) {

        shareIntent.putExtra(Intent.EXTRA_TEXT, resources.getString(string.sharecontent_email_text));
        shareIntent.putExtra(Intent.EXTRA_SUBJECT, resources.getString(string.sharecontent_subject));
        shareIntent.setType("message/rfc822");
        requestCode = RS_CODE_SHARE_GMAIL;
    }

    startActivityForResult(shareIntent, requestCode);
}

From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.messagehandler.MessageHandler.java

/**
 * Sends all available event types from the advertisementHashMap as an announcement using the package names for explicit addressing.
 * @param packageName used to setPackageName(packageName)
 *///w  ww.j  a va  2 s  . com
private void sendAllAvailableEventTypes(String packageName) {
    String[] availableEventTypes = getAllAvailableEvents();
    Announcement announcement = new Announcement(evtUtils.getEventID(), evtUtils.getTimestamp(), TAG, "",
            getPackageName(), Announcement.ALL_AVAILABLE_EVENT_TYPES);

    Intent intent = new Intent();
    intent.putExtra(Event.PARCELABLE_EXTRA_EVENT_TYPE, announcement.getEventType());
    intent.putExtra(Event.PARCELABLE_EXTRA_EVENT, announcement);
    intent.putExtra(Event.PARCELABLE_EXTRA_AVAILABLE_EVENTS, availableEventTypes);
    if (D)
        Log.d(TAG, "availableEventTypes String[]" + availableEventTypes);
    //Implicit addressing
    intent.setAction(AbstractChannel.MANAGEMENT);
    //Explicit addressing
    intent.setPackage(packageName);
    getApplicationContext().sendBroadcast(intent);
}

From source file:com.partypoker.poker.engagement.reach.EngagementReachAgent.java

/**
 * Try to notify the content to the user.
 * @param content reach content.//from   w w  w  .  j  av a  2s  . c o  m
 * @param replaySystemNotifications true iff system notifications must be replayed.
 * @throws RuntimeException if an error occurs.
 */
private void notifyContent(final EngagementReachContent content, boolean replaySystemNotifications)
        throws RuntimeException {
    /* Check expiry */
    final long localId = content.getLocalId();
    if (content.hasExpired()) {
        /* Delete */
        deleteContent(content);
        return;
    }

    /* If datapush, just broadcast, can be done in parallel with another content */
    final Intent intent = content.getIntent();
    if (content instanceof com.microsoft.azure.engagement.reach.EngagementDataPush) {
        /* Delay data push until DLC completes */
        if (!checkRequestDlc(content))
            return;

        /* If it's a datapush it may already be in the process of broadcasting. */
        if (!mPendingDataPushes.add(localId))
            return;

        /* Broadcast intent */
        final com.microsoft.azure.engagement.reach.EngagementDataPush dataPush = (EngagementDataPush) content;
        intent.setPackage(mContext.getPackageName());
        mContext.sendOrderedBroadcast(intent, null, new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                /* The last broadcast receiver to set a defined result wins (to determine which result). */
                switch (getResultCode()) {
                case RESULT_OK:
                    dataPush.actionContent(context);
                    break;

                case RESULT_CANCELED:
                    dataPush.exitContent(context);
                    break;

                default:
                    dataPush.dropContent(context);
                }

                /* Clean broadcast state */
                mPendingDataPushes.remove(localId);
            }
        }, null, RESULT_UNDEFINED, null, null);

        /* Datapush processed */
        return;
    }

    /* If notification has pending downloadable content, delay */
    if (content.hasNotificationDLC() && !checkRequestDlc(content))
        return;

    /* Don't notify in-app if we are already notifying in app or showing a content */
    if (mState != State.IDLE && !content.isSystemNotification())
        return;

    /* Don't process again a pending notification */
    if (mPendingNotifications.contains(localId))
        return;

    /* Not an interactive content, exit (but there is no other type left, this is just a cast guard) */
    if (!(content instanceof EngagementReachInteractiveContent))
        return;
    EngagementReachInteractiveContent iContent = (EngagementReachInteractiveContent) content;

    /* Don't replay system notification unless told otherwise. */
    if (!replaySystemNotifications && iContent.isSystemNotification()
            && iContent.getNotificationLastDisplayedDate() != null
            && iContent.getNotificationLastDisplayedDate() > mAppLastUpdateTime)
        return;

    /* Check if the content can be notified in the current context (behavior) */
    if (!iContent.canNotify(sActivityManager.getCurrentActivityAlias()))
        return;

    /* If there is a show intent */
    if (intent != null)
        filterIntentWithCategory(intent);

    /* Delegate notification */
    Boolean notifierResult = getNotifier(content).handleNotification(iContent);

    /* Check if notifier rejected content notification for now */
    if (Boolean.FALSE.equals(notifierResult))

        /* The notifier rejected the content, nothing more to do */
        return;

    /* Cache content if accepted, it will most likely be used again soon for the next steps. */
    mContentCache.put(localId, content);

    /*
     * If notifier did not return null (e.g. returned true, meaning actually accepted the content),
     * we assume the notification is correctly displayed.
     */
    if (Boolean.TRUE.equals(notifierResult)) {
        /* Report displayed feedback */
        iContent.displayNotification(mContext);

        /* Track in-app content life cycle: one at a time */
        if (!iContent.isSystemNotification())
            mState = State.NOTIFYING_IN_APP;
    }

    /* Track pending notifications to avoid re-processing them every time we change activity. */
    if (notifierResult == null)
        mPendingNotifications.add(localId);
}