Example usage for android.content Intent getLongArrayExtra

List of usage examples for android.content Intent getLongArrayExtra

Introduction

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

Prototype

public long[] getLongArrayExtra(String name) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:com.fenlisproject.elf.core.framework.ElfBinder.java

public static void bindIntentExtra(Object receiver) {
    Field[] fields = receiver.getClass().getDeclaredFields();
    for (Field field : fields) {
        field.setAccessible(true);/*from   w  w  w . j  ava  2  s. co  m*/
        IntentExtra intentExtra = field.getAnnotation(IntentExtra.class);
        if (intentExtra != null) {
            try {
                Intent intent = null;
                if (receiver instanceof Activity) {
                    intent = ((Activity) receiver).getIntent();
                } else if (receiver instanceof Fragment) {
                    intent = ((Fragment) receiver).getActivity().getIntent();
                }
                if (intent != null) {
                    Class<?> type = field.getType();
                    if (type == Boolean.class || type == boolean.class) {
                        field.set(receiver, intent.getBooleanExtra(intentExtra.value(), false));
                    } else if (type == Byte.class || type == byte.class) {
                        field.set(receiver, intent.getByteExtra(intentExtra.value(), (byte) 0));
                    } else if (type == Character.class || type == char.class) {
                        field.set(receiver, intent.getCharExtra(intentExtra.value(), '\u0000'));
                    } else if (type == Double.class || type == double.class) {
                        field.set(receiver, intent.getDoubleExtra(intentExtra.value(), 0.0d));
                    } else if (type == Float.class || type == float.class) {
                        field.set(receiver, intent.getFloatExtra(intentExtra.value(), 0.0f));
                    } else if (type == Integer.class || type == int.class) {
                        field.set(receiver, intent.getIntExtra(intentExtra.value(), 0));
                    } else if (type == Long.class || type == long.class) {
                        field.set(receiver, intent.getLongExtra(intentExtra.value(), 0L));
                    } else if (type == Short.class || type == short.class) {
                        field.set(receiver, intent.getShortExtra(intentExtra.value(), (short) 0));
                    } else if (type == String.class) {
                        field.set(receiver, intent.getStringExtra(intentExtra.value()));
                    } else if (type == Boolean[].class || type == boolean[].class) {
                        field.set(receiver, intent.getBooleanArrayExtra(intentExtra.value()));
                    } else if (type == Byte[].class || type == byte[].class) {
                        field.set(receiver, intent.getByteArrayExtra(intentExtra.value()));
                    } else if (type == Character[].class || type == char[].class) {
                        field.set(receiver, intent.getCharArrayExtra(intentExtra.value()));
                    } else if (type == Double[].class || type == double[].class) {
                        field.set(receiver, intent.getDoubleArrayExtra(intentExtra.value()));
                    } else if (type == Float[].class || type == float[].class) {
                        field.set(receiver, intent.getFloatArrayExtra(intentExtra.value()));
                    } else if (type == Integer[].class || type == int[].class) {
                        field.set(receiver, intent.getIntArrayExtra(intentExtra.value()));
                    } else if (type == Long[].class || type == long[].class) {
                        field.set(receiver, intent.getLongArrayExtra(intentExtra.value()));
                    } else if (type == Short[].class || type == short[].class) {
                        field.set(receiver, intent.getShortArrayExtra(intentExtra.value()));
                    } else if (type == String[].class) {
                        field.set(receiver, intent.getStringArrayExtra(intentExtra.value()));
                    } else if (Serializable.class.isAssignableFrom(type)) {
                        field.set(receiver, intent.getSerializableExtra(intentExtra.value()));
                    } else if (type == Bundle.class) {
                        field.set(receiver, intent.getBundleExtra(intentExtra.value()));
                    }
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:og.android.tether.MainActivity.java

public MainActivity() {

    intentReceiver = new BroadcastReceiver() {
        @Override/*www .jav a2s. c  o m*/
        public void onReceive(Context context, Intent intent) {
            Log.d(MSG_TAG, "onReceive() " + intent);
            String action = intent.getAction();
            if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
                int temp = (intent.getIntExtra("temperature", 0));
                MainActivity.this.application.lastTemperature = temp;
                int celsius = (int) ((temp + 5) / 10);
                int fahrenheit = (int) (((temp / 10) / 0.555) + 32 + 0.5);
                Log.d(MSG_TAG,
                        "Temp ==> " + temp + " -- Celsius ==> " + celsius + " -- Fahrenheit ==> " + fahrenheit);
                if (MainActivity.this.application.settings.getString("batterytemppref", "celsius")
                        .equals("celsius")) {
                    batteryTemperature
                            .setText("" + celsius + getString(R.string.main_activity_temperatureunit_celsius));
                } else {
                    batteryTemperature.setText(
                            "" + fahrenheit + getString(R.string.main_activity_temperatureunit_fahrenheit));
                }
            } else {
                //Log.d(MSG_TAG, "INTENT RECEIVED: "+intent.getAction());
                if (action.equals(TetherService.INTENT_TRAFFIC))
                    updateTrafficDisplay(intent.getLongArrayExtra("traffic_count"));
                if (action.equals(TetherService.INTENT_STATE)) {
                    Log.d(MSG_TAG, "STATE RECEIVED: " + intent.getIntExtra("state", 999));
                    try {
                        switch (intent.getIntExtra("state", TetherService.STATE_IDLE)) {
                        case TetherService.STATE_RESTARTING:
                            try {
                                MainActivity.this.dismissDialog(MainActivity.ID_DIALOG_STOPPING);
                            } catch (Exception e) {
                            }
                            break;
                        case TetherService.STATE_STARTING:
                            MainActivity.this.showDialog(MainActivity.ID_DIALOG_STARTING);
                            break;
                        case TetherService.STATE_RUNNING:
                            try {
                                MainActivity.this.dismissDialog(MainActivity.ID_DIALOG_STARTING);
                            } catch (Exception e) {
                            }
                            MainActivity.this.toggleStartStop();
                            break;
                        case TetherService.STATE_STOPPING:
                            MainActivity.this.showDialog(MainActivity.ID_DIALOG_STOPPING);
                            break;
                        case TetherService.STATE_IDLE:
                            try {
                                MainActivity.this.dismissDialog(MainActivity.ID_DIALOG_STOPPING);
                            } catch (Exception e) {
                            }
                            MainActivity.this.toggleStartStop();
                            break;
                        case TetherService.STATE_FAIL_LOG:
                            try {
                                MainActivity.this.dismissDialog(MainActivity.ID_DIALOG_STARTING);
                            } catch (Exception e) {
                            }
                            MainActivity.this.application
                                    .displayToastMessage(getString(R.string.main_activity_start_errors));
                            MainActivity.this.toggleStartStop();
                            break;
                        case TetherService.STATE_FAIL_EXEC_START:
                            try {
                                MainActivity.this.dismissDialog(MainActivity.ID_DIALOG_STARTING);
                            } catch (Exception e) {
                            }
                            MainActivity.this.application
                                    .displayToastMessage(getString(R.string.main_activity_start_unable));
                            MainActivity.this.toggleStartStop();
                            break;
                        case TetherService.STATE_FAIL_EXEC_STOP:
                            try {
                                MainActivity.this.dismissDialog(MainActivity.ID_DIALOG_STOPPING);
                            } catch (Exception e) {
                            }
                            MainActivity.this.toggleStartStop();
                            break;
                        }

                    } catch (Exception e) {
                    } finally {
                        // MainActivity.this.toggleStartStop();
                    }

                } else if (action.equals(RSSReader.MESSAGE_JSON_RSS)) {
                    updateRSSView(intent.getStringExtra(RSSReader.EXTRA_JSON_RSS));
                }
            }

        }
    };

    // ??? deprecated?
    viewUpdateHandler = new Handler() {
        public void handleMessage(Message msg) {
            Log.d(MSG_TAG, "MESSAGE: " + msg);
            switch (msg.what) {
            case MESSAGE_CHECK_LOG:
                Log.d(MSG_TAG, "Error detected. Check log.");
                MainActivity.this.application
                        .displayToastMessage(getString(R.string.main_activity_start_errors));
                MainActivity.this.toggleStartStop();
                break;
            case MESSAGE_CANT_START_TETHER:
                Log.d(MSG_TAG, "Unable to start tethering!");
                MainActivity.this.application
                        .displayToastMessage(getString(R.string.main_activity_start_unable));
                MainActivity.this.toggleStartStop();
                break;
            case MESSAGE_TRAFFIC_START:
                MainActivity.this.trafficRow.setVisibility(View.VISIBLE);
                break;
            case MESSAGE_TRAFFIC_COUNT:
                MainActivity.this.trafficRow.setVisibility(View.VISIBLE);
                //???
                long uploadTraffic = ((TetherService.DataCount) msg.obj).totalUpload;
                long downloadTraffic = ((TetherService.DataCount) msg.obj).totalDownload;
                long uploadRate = ((TetherService.DataCount) msg.obj).uploadRate;
                long downloadRate = ((TetherService.DataCount) msg.obj).downloadRate;

                // Set rates to 0 if values are negative
                if (uploadRate < 0)
                    uploadRate = 0;
                if (downloadRate < 0)
                    downloadRate = 0;

                MainActivity.this.uploadText.setText(MainActivity.this.formatCount(uploadTraffic, false));
                MainActivity.this.downloadText.setText(MainActivity.this.formatCount(downloadTraffic, false));
                MainActivity.this.downloadText.invalidate();
                MainActivity.this.uploadText.invalidate();

                MainActivity.this.uploadRateText.setText(MainActivity.this.formatCount(uploadRate, true));
                MainActivity.this.downloadRateText.setText(MainActivity.this.formatCount(downloadRate, true));
                MainActivity.this.downloadRateText.invalidate();
                MainActivity.this.uploadRateText.invalidate();
                break;
            case MESSAGE_TRAFFIC_END:
                MainActivity.this.trafficRow.setVisibility(View.INVISIBLE);
                break;
            case MESSAGE_DOWNLOAD_STARTING:
                Log.d(MSG_TAG, "Start progress bar");
                MainActivity.this.progressBar.setIndeterminate(true);
                MainActivity.this.progressTitle.setText((String) msg.obj);
                MainActivity.this.progressText.setText("Starting...");
                MainActivity.this.downloadUpdateLayout.setVisibility(View.VISIBLE);
                break;
            case MESSAGE_DOWNLOAD_PROGRESS:
                MainActivity.this.progressBar.setIndeterminate(false);
                MainActivity.this.progressText.setText(msg.arg1 + "k /" + msg.arg2 + "k");
                MainActivity.this.progressBar.setProgress(msg.arg1 * 100 / msg.arg2);
                break;
            case MESSAGE_DOWNLOAD_COMPLETE:
                Log.d(MSG_TAG, "Finished download.");
                MainActivity.this.progressText.setText("");
                MainActivity.this.progressTitle.setText("");
                MainActivity.this.downloadUpdateLayout.setVisibility(View.GONE);
                break;
            case MESSAGE_DOWNLOAD_BLUETOOTH_COMPLETE:
                Log.d(MSG_TAG, "Finished bluetooth download.");
                MainActivity.this.startBtn.setClickable(true);
                MainActivity.this.radioModeLabel.setText("Bluetooth");
                break;
            case MESSAGE_DOWNLOAD_BLUETOOTH_FAILED:
                Log.d(MSG_TAG, "FAILED bluetooth download.");
                MainActivity.this.startBtn.setClickable(true);
                MainActivity.this.application.preferenceEditor.putBoolean("bluetoothon", false);
                MainActivity.this.application.preferenceEditor.commit();
                // TODO: More detailed popup info.
                MainActivity.this.application.displayToastMessage(
                        "No bluetooth module for your kernel! Please report your kernel version.");
            default:
                MainActivity.this.toggleStartStop();
            }
            super.handleMessage(msg);
        }
    };

}

From source file:com.mobicage.rogerthat.util.ui.SendMessageView.java

public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    switch (requestCode) {
    case PICK_IMAGE:
        if (resultCode == Activity.RESULT_OK) {
            if (mUriSavedFile == null) {
                setupUploadFile("jpg", false);
            }/*from   ww  w  .  ja  v a  2  s .  c o  m*/
            mUploadFileExtenstion = AttachmentViewerActivity.CONTENT_TYPE_JPEG;
            if (data != null && data.getData() != null) {
                final Uri selectedImage = data.getData();
                setFileExtemsionFromUri(selectedImage);
                setAttachmentSelected(selectedImage);
            } else {
                setFileExtemsionFromUri(mUriSavedFile);
                setAttachmentSelected(mUriSavedFile);
            }
        }
        break;
    case PICK_VIDEO:
        if (resultCode == Activity.RESULT_OK) {
            if (mUriSavedFile == null) {
                setupUploadFile("mp4", false);
            }
            mUploadFileExtenstion = AttachmentViewerActivity.CONTENT_TYPE_VIDEO_MP4;
            if (data != null && data.getData() != null) {
                final Uri selectedVideo = data.getData();
                setFileExtemsionFromUri(selectedVideo);
                setAttachmentSelected(selectedVideo);
            } else {
                setFileExtemsionFromUri(mUriSavedFile);
                setAttachmentSelected(mUriSavedFile);
            }
        }
        break;

    case PICK_BUTTON:
        if (resultCode == Activity.RESULT_OK) {
            try {
                mCannedButtons = (CannedButtons) Pickler.createObjectFromPickle(
                        data.getByteArrayExtra(SendMessageButtonActivity.CANNED_BUTTONS));
                mButtons = new LinkedHashSet<>();
                mButtonsContainer.removeAllViews();
                long[] buttons = data.getLongArrayExtra(SendMessageButtonActivity.BUTTONS);
                if (buttons != null) {
                    for (final long l : buttons) {
                        mButtons.add(l);

                        CannedButton cannedButton = mCannedButtons.getById(l);
                        if (cannedButton == null)
                            continue;

                        final View previewButtonContainer = mActivity.getLayoutInflater()
                                .inflate(R.layout.chat_container_message_button, null);
                        final Button previewButton = (Button) previewButtonContainer.findViewById(R.id.button);
                        previewButton.setText(cannedButton.getCaption());
                        previewButton.setOnClickListener(new SafeViewOnClickListener() {
                            @Override
                            public void safeOnClick(View v) {
                                mButtons.remove(l);
                                mButtonsContainer.removeView(previewButtonContainer);
                            }
                        });
                        mButtonsContainer.addView(previewButtonContainer);
                    }
                }
            } catch (Exception e) {
                L.bug(e);
            }
        }
        break;

    }
}

From source file:com.otaupdater.DownloadReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (action == null)
        return;/*w  w w  .  java  2  s .  c  o  m*/

    if (action.equals(DL_ROM_ACTION)) {
        RomInfo.FACTORY.clearUpdateNotif(context);
        RomInfo.FACTORY.fromIntent(intent).startDownload(context);
    } else if (action.equals(DL_KERNEL_ACTION)) {
        KernelInfo.FACTORY.clearUpdateNotif(context);
        KernelInfo.FACTORY.fromIntent(intent).startDownload(context);
    } else if (action.equals(CLEAR_DL_ACTION)) {
        if (intent.hasExtra(DownloadManager.EXTRA_DOWNLOAD_ID)) {
            DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
            dm.remove(intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1));
            DownloadBarFragment.notifyActiveFragment();
        }
    } else if (action.equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) {
        DownloadStatus status = DownloadStatus.forDownloadID(context,
                intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1));
        if (status == null)
            return;

        BaseInfo info = status.getInfo();
        if (info == null)
            return;

        int error = status.getStatus() == DownloadManager.STATUS_SUCCESSFUL ? info.checkDownloadedFile()
                : status.getReason();

        NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        if (error == 0) {
            Intent mainIntent = new Intent(context, OTAUpdaterActivity.class);
            mainIntent.setAction(info.getNotifAction());
            mainIntent.putExtra(OTAUpdaterActivity.EXTRA_FLAG_DOWNLOAD_DIALOG, true);
            PendingIntent mainPIntent = PendingIntent.getActivity(context, 0, mainIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Intent flashIntent = new Intent(context, DownloadsActivity.class);
            flashIntent.setAction(info.getFlashAction());
            info.addToIntent(flashIntent);
            PendingIntent flashPIntent = PendingIntent.getActivity(context, 0, flashIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Notification notif = new NotificationCompat.Builder(context)
                    .setTicker(context.getString(info.getDownloadDoneTitle()))
                    .setContentTitle(context.getString(info.getDownloadDoneTitle()))
                    .setSmallIcon(R.drawable.ic_stat_av_download)
                    .setContentText(context.getString(R.string.notif_completed)).setContentIntent(mainPIntent)
                    .addAction(R.drawable.ic_action_system_update, context.getString(R.string.install),
                            flashPIntent)
                    .build();
            nm.notify(info.getFlashNotifID(), notif);
        } else {
            Intent mainIntent = new Intent(context, OTAUpdaterActivity.class);
            mainIntent.setAction(info.getNotifAction());
            info.addToIntent(mainIntent);
            PendingIntent mainPIntent = PendingIntent.getActivity(context, 0, mainIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Intent dlIntent = new Intent(context, DownloadReceiver.class);
            dlIntent.setAction(info.getDownloadAction());
            info.addToIntent(dlIntent);
            PendingIntent dlPIntent = PendingIntent.getBroadcast(context, 1, dlIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Intent clearIntent = new Intent(context, DownloadReceiver.class);
            clearIntent.setAction(CLEAR_DL_ACTION);
            clearIntent.putExtra(DownloadManager.EXTRA_DOWNLOAD_ID, status.getId());
            PendingIntent clearPIntent = PendingIntent.getBroadcast(context, 2, clearIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Notification notif = new NotificationCompat.Builder(context)
                    .setTicker(context.getString(info.getDownloadFailedTitle()))
                    .setContentTitle(context.getString(info.getDownloadFailedTitle()))
                    .setContentText(status.getErrorString(context)).setSmallIcon(R.drawable.ic_stat_warning)
                    .setContentIntent(mainPIntent).setDeleteIntent(clearPIntent)
                    .addAction(R.drawable.ic_action_refresh, context.getString(R.string.retry), dlPIntent)
                    .build();
            nm.notify(info.getFailedNotifID(), notif);
        }
    } else if (action.equals(DownloadManager.ACTION_NOTIFICATION_CLICKED)) {
        long[] ids = intent.getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS);
        if (ids.length == 0)
            return;

        DownloadStatus status = DownloadStatus.forDownloadID(context, ids[0]);
        if (status == null)
            return;

        BaseInfo info = status.getInfo();
        if (info == null)
            return;

        Intent i = new Intent(context, OTAUpdaterActivity.class);
        i.setAction(info.getNotifAction());
        i.putExtra(OTAUpdaterActivity.EXTRA_FLAG_DOWNLOAD_DIALOG, true);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
    }
}

From source file:com.nks.nksmod.otaupdater.DownloadReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (action == null)
        return;//from ww  w  .j a  v a2  s. c  o  m

    if (action.equals(DL_ROM_ACTION)) {
        RomInfo.FACTORY.clearUpdateNotif(context);
        RomInfo.FACTORY.fromIntent(intent).startDownload(context);
        /* } else if (action.equals(DL_KERNEL_ACTION)) {
            KernelInfo.FACTORY.clearUpdateNotif(context);
            KernelInfo.FACTORY.fromIntent(intent).startDownload(context); */
    } else if (action.equals(CLEAR_DL_ACTION)) {
        if (intent.hasExtra(DownloadManager.EXTRA_DOWNLOAD_ID)) {
            DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
            dm.remove(intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1));
            DownloadBarFragment.notifyActiveFragment();
        }
    } else if (action.equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) {
        DownloadStatus status = DownloadStatus.forDownloadID(context,
                intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1));
        if (status == null)
            return;

        BaseInfo info = status.getInfo();
        if (info == null)
            return;

        int error = status.getStatus() == DownloadManager.STATUS_SUCCESSFUL ? info.checkDownloadedFile()
                : status.getReason();

        NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        if (error == 0) {
            Intent mainIntent = new Intent(context, OTAUpdaterActivity.class);
            mainIntent.setAction(info.getNotifAction());
            mainIntent.putExtra(OTAUpdaterActivity.EXTRA_FLAG_DOWNLOAD_DIALOG, true);
            PendingIntent mainPIntent = PendingIntent.getActivity(context, 0, mainIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Intent flashIntent = new Intent(context, DownloadsActivity.class);
            flashIntent.setAction(info.getFlashAction());
            info.addToIntent(flashIntent);
            PendingIntent flashPIntent = PendingIntent.getActivity(context, 0, flashIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Notification notif = new NotificationCompat.Builder(context)
                    .setTicker(context.getString(info.getDownloadDoneTitle()))
                    .setContentTitle(context.getString(info.getDownloadDoneTitle()))
                    .setSmallIcon(R.drawable.ic_stat_av_download)
                    .setContentText(context.getString(R.string.notif_completed)).setContentIntent(mainPIntent)
                    .addAction(R.drawable.ic_action_system_update, context.getString(R.string.install),
                            flashPIntent)
                    .build();
            nm.notify(info.getFlashNotifID(), notif);
        } else {
            Intent mainIntent = new Intent(context, OTAUpdaterActivity.class);
            mainIntent.setAction(info.getNotifAction());
            info.addToIntent(mainIntent);
            PendingIntent mainPIntent = PendingIntent.getActivity(context, 0, mainIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Intent dlIntent = new Intent(context, DownloadReceiver.class);
            dlIntent.setAction(info.getDownloadAction());
            info.addToIntent(dlIntent);
            PendingIntent dlPIntent = PendingIntent.getBroadcast(context, 1, dlIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Intent clearIntent = new Intent(context, DownloadReceiver.class);
            clearIntent.setAction(CLEAR_DL_ACTION);
            clearIntent.putExtra(DownloadManager.EXTRA_DOWNLOAD_ID, status.getId());
            PendingIntent clearPIntent = PendingIntent.getBroadcast(context, 2, clearIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Notification notif = new NotificationCompat.Builder(context)
                    .setTicker(context.getString(info.getDownloadFailedTitle()))
                    .setContentTitle(context.getString(info.getDownloadFailedTitle()))
                    .setContentText(status.getErrorString(context)).setSmallIcon(R.drawable.ic_stat_warning)
                    .setContentIntent(mainPIntent).setDeleteIntent(clearPIntent)
                    .addAction(R.drawable.ic_action_refresh, context.getString(R.string.retry), dlPIntent)
                    .build();
            nm.notify(info.getFailedNotifID(), notif);
        }
    } else if (action.equals(DownloadManager.ACTION_NOTIFICATION_CLICKED)) {
        long[] ids = intent.getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS);
        if (ids.length == 0)
            return;

        DownloadStatus status = DownloadStatus.forDownloadID(context, ids[0]);
        if (status == null)
            return;

        BaseInfo info = status.getInfo();
        if (info == null)
            return;

        Intent i = new Intent(context, OTAUpdaterActivity.class);
        i.setAction(info.getNotifAction());
        i.putExtra(OTAUpdaterActivity.EXTRA_FLAG_DOWNLOAD_DIALOG, true);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
    }
}

From source file:com.mobicage.rogerthat.plugins.friends.ActionScreenActivity.java

@SuppressLint({ "SetJavaScriptEnabled", "JavascriptInterface", "NewApi" })
@Override//from   w w  w. ja va2 s. c o  m
public void onCreate(Bundle savedInstanceState) {
    if (CloudConstants.isContentBrandingApp()) {
        super.setTheme(android.R.style.Theme_Black_NoTitleBar_Fullscreen);
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.action_screen);
    mBranding = (WebView) findViewById(R.id.branding);
    WebSettings brandingSettings = mBranding.getSettings();
    brandingSettings.setJavaScriptEnabled(true);
    brandingSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        brandingSettings.setAllowFileAccessFromFileURLs(true);
    }
    mBrandingHttp = (WebView) findViewById(R.id.branding_http);
    mBrandingHttp.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    WebSettings brandingSettingsHttp = mBrandingHttp.getSettings();
    brandingSettingsHttp.setJavaScriptEnabled(true);
    brandingSettingsHttp.setCacheMode(WebSettings.LOAD_DEFAULT);

    if (CloudConstants.isContentBrandingApp()) {
        mSoundThread = new HandlerThread("rogerthat_actionscreenactivity_sound");
        mSoundThread.start();
        Looper looper = mSoundThread.getLooper();
        mSoundHandler = new Handler(looper);

        int cameraPermission = ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
        if (cameraPermission == PackageManager.PERMISSION_GRANTED) {
            mQRCodeScanner = QRCodeScanner.getInstance(this);
            final LinearLayout previewHolder = (LinearLayout) findViewById(R.id.preview_view);
            previewHolder.addView(mQRCodeScanner.view);
        }
        mBranding.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                initFullScreenForContentBranding();
            }
        });

        mBrandingHttp.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                initFullScreenForContentBranding();
            }
        });
    }

    final View brandingHeader = findViewById(R.id.branding_header_container);

    final ImageView brandingHeaderClose = (ImageView) findViewById(R.id.branding_header_close);
    final TextView brandingHeaderText = (TextView) findViewById(R.id.branding_header_text);
    brandingHeaderClose
            .setColorFilter(UIUtils.imageColorFilter(getResources().getColor(R.color.mc_homescreen_text)));

    brandingHeaderClose.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mQRCodeScanner != null) {
                mQRCodeScanner.onResume();
            }
            brandingHeader.setVisibility(View.GONE);
            mBrandingHttp.setVisibility(View.GONE);
            mBranding.setVisibility(View.VISIBLE);
            mBrandingHttp.loadUrl("about:blank");
        }
    });

    final View brandingFooter = findViewById(R.id.branding_footer_container);

    if (CloudConstants.isContentBrandingApp()) {
        brandingHeaderClose.setVisibility(View.GONE);
        final ImageView brandingFooterClose = (ImageView) findViewById(R.id.branding_footer_close);
        final TextView brandingFooterText = (TextView) findViewById(R.id.branding_footer_text);
        brandingFooterText.setText(getString(R.string.back));
        brandingFooterClose
                .setColorFilter(UIUtils.imageColorFilter(getResources().getColor(R.color.mc_homescreen_text)));

        brandingFooter.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mQRCodeScanner != null) {
                    mQRCodeScanner.onResume();
                }
                brandingHeader.setVisibility(View.GONE);
                brandingFooter.setVisibility(View.GONE);
                mBrandingHttp.setVisibility(View.GONE);
                mBranding.setVisibility(View.VISIBLE);
                mBrandingHttp.loadUrl("about:blank");
            }
        });
    }

    final RelativeLayout openPreview = (RelativeLayout) findViewById(R.id.preview_holder);

    openPreview.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mQRCodeScanner != null) {
                mQRCodeScanner.previewHolderClicked();
            }
        }
    });

    mBranding.addJavascriptInterface(new JSInterface(this), "__rogerthat__");
    mBranding.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onConsoleMessage(String message, int lineNumber, String sourceID) {
            if (sourceID != null) {
                try {
                    sourceID = new File(sourceID).getName();
                } catch (Exception e) {
                    L.d("Could not get fileName of sourceID: " + sourceID, e);
                }
            }
            if (mIsHtmlContent) {
                L.i("[BRANDING] " + sourceID + ":" + lineNumber + " | " + message);
            } else {
                L.d("[BRANDING] " + sourceID + ":" + lineNumber + " | " + message);
            }
        }
    });
    mBranding.setWebViewClient(new WebViewClient() {
        private boolean isExternalUrl(String url) {
            for (String regularExpression : mBrandingResult.externalUrlPatterns) {
                if (url.matches(regularExpression)) {
                    return true;
                }
            }
            return false;
        }

        @SuppressLint("DefaultLocale")
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            L.i("Branding is loading url: " + url);
            Uri uri = Uri.parse(url);
            String lowerCaseUrl = url.toLowerCase();
            if (lowerCaseUrl.startsWith("tel:") || lowerCaseUrl.startsWith("mailto:") || isExternalUrl(url)) {
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                startActivity(intent);
                return true;
            } else if (lowerCaseUrl.startsWith(POKE)) {
                String tag = url.substring(POKE.length());
                poke(tag);
                return true;
            } else if (lowerCaseUrl.startsWith("http://") || lowerCaseUrl.startsWith("https://")) {
                if (mQRCodeScanner != null) {
                    mQRCodeScanner.onPause();
                }
                brandingHeaderText.setText(getString(R.string.loading));
                brandingHeader.setVisibility(View.VISIBLE);
                if (CloudConstants.isContentBrandingApp()) {
                    brandingFooter.setVisibility(View.VISIBLE);
                }
                mBranding.setVisibility(View.GONE);
                mBrandingHttp.setVisibility(View.VISIBLE);
                mBrandingHttp.loadUrl(url);
                return true;
            } else {
                brandingHeader.setVisibility(View.GONE);
                brandingFooter.setVisibility(View.GONE);
                mBrandingHttp.setVisibility(View.GONE);
                mBranding.setVisibility(View.VISIBLE);
            }
            return false;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            L.i("onPageFinished " + url);
            if (!mInfoSet && mService != null && mIsHtmlContent) {
                Map<String, Object> info = mFriendsPlugin.getRogerthatUserAndServiceInfo(mServiceEmail,
                        mServiceFriend);

                executeJS(true, "if (typeof rogerthat !== 'undefined') rogerthat._setInfo(%s)",
                        JSONValue.toJSONString(info));
                mInfoSet = true;
            }
        }

        @Override
        public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
            L.i("Checking access to: '" + url + "'");
            final URL parsedUrl;
            try {
                parsedUrl = new URL(url);
            } catch (MalformedURLException e) {
                L.d("Webview tried to load malformed URL");
                return new WebResourceResponse("text/plain", "UTF-8", null);
            }
            if (!parsedUrl.getProtocol().equals("file")) {
                return null;
            }
            File urlPath = new File(parsedUrl.getPath());
            if (urlPath.getAbsolutePath().startsWith(mBrandingResult.dir.getAbsolutePath())) {
                return null;
            }
            L.d("404: Webview tries to load outside its sandbox.");
            return new WebResourceResponse("text/plain", "UTF-8", null);
        }
    });

    mBrandingHttp.setWebViewClient(new WebViewClient() {
        @SuppressLint("DefaultLocale")
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            L.i("BrandingHttp is loading url: " + url);
            return false;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            brandingHeaderText.setText(view.getTitle());
            L.i("onPageFinished " + url);
        }
    });

    Intent intent = getIntent();
    mBrandingKey = intent.getStringExtra(BRANDING_KEY);
    mServiceEmail = intent.getStringExtra(SERVICE_EMAIL);
    mItemTagHash = intent.getStringExtra(ITEM_TAG_HASH);
    mItemLabel = intent.getStringExtra(ITEM_LABEL);
    mItemCoords = intent.getLongArrayExtra(ITEM_COORDS);
    mRunInBackground = intent.getBooleanExtra(RUN_IN_BACKGROUND, true);
}

From source file:com.tct.mail.compose.ComposeActivity.java

@Override
protected void onActivityResult(int request, int result, Intent data) {
    if (request == RESULT_PICK_ATTACHMENT) {
        mAddingAttachment = false;//from w  ww  .  j  ava 2s. c o  m
        if (result == RESULT_OK) {
            addAttachmentAndUpdateView(data);
        }
    } else if (request == RESULT_CREATE_ACCOUNT) {
        // We were waiting for the user to create an account
        if (result != RESULT_OK) {
            finish();
        } else {
            // Watch for accounts to show up!
            // restart the loader to get the updated list of accounts
            getLoaderManager().initLoader(LOADER_ACCOUNT_CURSOR, null, this);
            showWaitFragment(null);
        } //TS:kaifeng.lu 2015-10-28 EMAIL BUGFIX_824294 MOD_S
    } else if (result == RESULT_OK && request == ACTIVITY_REQUEST_PICK_CONTACT_TO) {
        //TS:kaifeng.lu 2015-10-28 EMAIL BUGFIX_824294 MOD_E
        // TS: junwei-xu 2015-07-17 EMAIL BUGFIX-1029180 ADD_S
        mLaunchContact = false;
        // TS: junwei-xu 2015-07-17 EMAIL BUGFIX-1029180 ADD_E
        //TS:kaifeng.lu 2015-10-28 EMAIL BUGFIX_824294 MOD_S
        String platform = PLFUtils.getString(this, "feature_email_platform");
        if (platform.equals(PLATFORM_QUALCOMM)) {
            addAddressFromData(mTo, data);
        } else if (platform.equals(PLATFORM_MTK)) {
            final long[] ids = data.getLongArrayExtra(EXTRA_PICK_DATA_RESULT);
            if (ids == null || ids.length <= 0) {
                return;
            }
            addAddressesToList(ids, mTo);
        }
    } else if (result == RESULT_OK && request == ACTIVITY_REQUEST_PICK_CONTACT_CC) {
        //TS:kaifeng.lu 2015-10-28 EMAIL BUGFIX_824294 MOD_E
        // TS: junwei-xu 2015-07-17 EMAIL BUGFIX-1029180 ADD_S
        mLaunchContact = false;
        // TS: junwei-xu 2015-07-17 EMAIL BUGFIX-1029180 ADD_E
        //TS:kaifeng.lu 2015-10-28 EMAIL BUGFIX_824294 MOD_S
        String platform = PLFUtils.getString(this, "feature_email_platform");
        if (platform.equals(PLATFORM_QUALCOMM)) {
            addAddressFromData(mCc, data);
        } else if (platform.equals(PLATFORM_MTK)) {
            final long[] ids = data.getLongArrayExtra(EXTRA_PICK_DATA_RESULT);
            if (ids == null || ids.length <= 0) {
                return;
            }
            addAddressesToList(ids, mCc);
        }
    } else if (result == RESULT_OK && request == ACTIVITY_REQUEST_PICK_CONTACT_BCC) {
        //TS:kaifeng.lu 2015-10-28 EMAIL BUGFIX_824294 MOD_E
        // TS: junwei-xu 2015-07-17 EMAIL BUGFIX-1029180 ADD_S
        mLaunchContact = false;
        // TS: junwei-xu 2015-07-17 EMAIL BUGFIX-1029180 ADD_E
        //TS:kaifeng.lu 2015-10-28 EMAIL BUGFIX_824294 MOD_S
        String platform = PLFUtils.getString(this, "feature_email_platform");
        if (platform.equals(PLATFORM_QUALCOMM)) {
            addAddressFromData(mBcc, data);
        } else if (platform.equals(PLATFORM_MTK)) {
            final long[] ids = data.getLongArrayExtra(EXTRA_PICK_DATA_RESULT);
            if (ids == null || ids.length <= 0) {
                return;
            }
            addAddressesToList(ids, mBcc);
        }
        //TS:kaifeng.lu 2015-10-28 EMAIL BUGFIX_824294 MOD_E
    }
}