Example usage for android.content Intent putParcelableArrayListExtra

List of usage examples for android.content Intent putParcelableArrayListExtra

Introduction

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

Prototype

public @NonNull Intent putParcelableArrayListExtra(String name, ArrayList<? extends Parcelable> value) 

Source Link

Document

Add extended data to the intent.

Usage

From source file:de.mkrtchyan.recoverytools.RecoveryTools.java

public void report(final boolean isCancelable) {
    final Dialog reportDialog = mNotifyer.createDialog(R.string.commentar, R.layout.dialog_comment, false,
            true);//from  w  w w  .j a  v  a2s .c o m
    new Thread(new Runnable() {
        @Override
        public void run() {
            /** Creates a report Email including a Comment and important device infos */
            final Button bGo = (Button) reportDialog.findViewById(R.id.bGo);
            bGo.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {

                    if (!Common.getBooleanPref(mContext, PREF_NAME, PREF_KEY_ADS))
                        Toast.makeText(mContext, R.string.please_ads, Toast.LENGTH_SHORT).show();
                    Toast.makeText(mContext, R.string.donate_to_support, Toast.LENGTH_SHORT).show();
                    try {
                        ArrayList<File> files = new ArrayList<File>();
                        File TestResults = new File(mContext.getFilesDir(), "results.txt");
                        try {
                            if (TestResults.exists()) {
                                if (TestResults.delete()) {
                                    FileOutputStream fos = openFileOutput(TestResults.getName(),
                                            Context.MODE_PRIVATE);
                                    fos.write(("Recovery-Tools:\n\n"
                                            + mShell.execCommand(
                                                    "ls -lR " + PathToRecoveryTools.getAbsolutePath())
                                            + "\nCache Tree:\n" + mShell.execCommand("ls -lR /cache") + "\n"
                                            + "\nMTD result:\n" + mShell.execCommand("cat /proc/mtd") + "\n"
                                            + "\nDevice Tree:\n\n" + mShell.execCommand("ls -lR /dev"))
                                                    .getBytes());
                                }
                                files.add(TestResults);
                            }
                        } catch (FileNotFoundException e) {
                            e.printStackTrace();
                        }
                        if (getPackageManager() != null) {
                            PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
                            EditText text = (EditText) reportDialog.findViewById(R.id.etComment);
                            String comment = "";
                            if (text.getText() != null)
                                comment = text.getText().toString();
                            Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
                            intent.setType("text/plain");
                            intent.putExtra(Intent.EXTRA_EMAIL,
                                    new String[] { "ashotmkrtchyan1995@gmail.com" });
                            intent.putExtra(Intent.EXTRA_SUBJECT, "Recovery-Tools report");
                            intent.putExtra(Intent.EXTRA_TEXT, "Package Infos:" + "\n\nName: "
                                    + pInfo.packageName + "\nVersionName: " + pInfo.versionName
                                    + "\nVersionCode: " + pInfo.versionCode + "\n\n\nProduct Info: "
                                    + "\n\nManufacture: " + android.os.Build.MANUFACTURER + "\nDevice: "
                                    + Build.DEVICE + " (" + mDevice.getDeviceName() + ")" + "\nBoard: "
                                    + Build.BOARD + "\nBrand: " + Build.BRAND + "\nModel: " + Build.MODEL
                                    + "\nFingerprint: " + Build.FINGERPRINT + "\nAndroid SDK Level: "
                                    + Build.VERSION.CODENAME + " (" + Build.VERSION.SDK_INT + ")"
                                    + "\nRecovery Supported: " + mDevice.isRecoverySupported()
                                    + "\nRecovery Path: " + mDevice.getRecoveryPath() + "\nRecovery Version: "
                                    + mDevice.getRecoveryVersion() + "\nRecovery MTD: "
                                    + mDevice.isRecoveryMTD() + "\nRecovery DD: " + mDevice.isRecoveryDD()
                                    + "\nKernel Supported: " + mDevice.isKernelSupported() + "\nKernel Path: "
                                    + mDevice.getKernelPath() + "\nKernel Version: "
                                    + mDevice.getKernelVersion() + "\nKernel MTD: " + mDevice.isKernelMTD()
                                    + "\nKernel DD: " + mDevice.isKernelDD() + "\n\nCWM: "
                                    + mDevice.isCwmSupported() + "\nTWRP: " + mDevice.isTwrpSupported()
                                    + "\nPHILZ: " + mDevice.isPhilzSupported()
                                    + "\n\n\n===========COMMENT==========\n" + comment
                                    + "\n===========COMMENT END==========\n" + "\n===========PREFS==========\n"
                                    + getAllPrefs() + "\n===========PREFS END==========\n");
                            File CommandLogs = new File(mContext.getFilesDir(), Shell.Logs);
                            if (CommandLogs.exists()) {
                                files.add(CommandLogs);
                            }
                            files.add(new File(getFilesDir(), "last_log.txt"));
                            ArrayList<Uri> uris = new ArrayList<Uri>();
                            for (File file : files) {
                                mShell.execCommand("cp " + file.getAbsolutePath() + " "
                                        + new File(mContext.getFilesDir(), file.getName()).getAbsolutePath());
                                file = new File(mContext.getFilesDir(), file.getName());
                                mToolbox.setFilePermissions(file, "644");
                                uris.add(Uri.fromFile(file));
                            }
                            intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
                            startActivity(Intent.createChooser(intent, "Send over Gmail"));
                            reportDialog.dismiss();
                        }
                    } catch (Exception e) {
                        reportDialog.dismiss();
                        Notifyer.showExceptionToast(mContext, TAG, e);
                    }
                }
            });
        }
    }).start();
    reportDialog.setCancelable(isCancelable);
    reportDialog.show();
}

From source file:com.dycode.jepretstory.mediachooser.fragment.VideoFragment.java

private void setAdapter() {
    int count = mCursor.getCount();

    if (count > 0) {
        mDataColumnIndex = mCursor.getColumnIndex(MEDIA_DATA);
        int mIdColumnIndex = mCursor.getColumnIndex(MediaStore.Video.Media._ID);
        int mBucketColumnIndex = mCursor.getColumnIndex(MediaStore.Video.Media.BUCKET_ID);
        int resColumnIndex = mCursor.getColumnIndex(MediaStore.Video.Media.RESOLUTION);
        int durColumnIndex = mCursor.getColumnIndex(MediaStore.Video.Media.DURATION);

        //move position to first element
        mCursor.moveToFirst();/*from ww w .  ja va  2  s .c o  m*/

        mGalleryModelList = new ArrayList<MediaModel>();
        for (int i = 0; i < count; i++) {
            mCursor.moveToPosition(i);
            String url = mCursor.getString(mDataColumnIndex);
            String id = mCursor.getString(mIdColumnIndex);
            String bucketId = mCursor.getString(mBucketColumnIndex);

            //mGalleryModelList.add(new MediaModel(url, false, MediaMode.VIDEO));

            //            boolean selected = false;
            //            if (mSelectedItems != null && mSelectedItems.size() > 0) {
            //               for(String currVidUrl: mSelectedItems) {
            //                  if (currVidUrl.equalsIgnoreCase(url)) {
            //                     selected = true;
            //                     break;
            //                  }
            //               }
            //            }

            MediaModel galleryModel = new MediaModel(bucketId, id, url, false, MediaType.VIDEO);
            if (mSelectedModels != null && mSelectedModels.size() > 0) {
                galleryModel.status = mSelectedModels.contains(galleryModel);
            }

            galleryModel.resolution = mCursor.getString(resColumnIndex);
            galleryModel.videoDuration = mCursor.getInt(durColumnIndex);

            mGalleryModelList.add(galleryModel);
        }

        mVideoAdapter = new GridViewAdapter(getActivity(), 0, mGalleryModelList, true);
        mVideoAdapter.videoFragment = this;
        mVideoGridView.setAdapter(mVideoAdapter);
        mVideoGridView.setOnScrollListener(this);

    } else {
        Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available),
                Toast.LENGTH_SHORT).show();

    }

    mVideoGridView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter();
            MediaModel galleryModel = (MediaModel) adapter.getItem(position);
            File file = new File(galleryModel.url);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.fromFile(file), "video/*");
            startActivity(intent);
            return false;
        }
    });

    mVideoGridView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // update the mStatus of each category in the adapter
            GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter();
            MediaModel galleryModel = (MediaModel) adapter.getItem(position);

            if (!galleryModel.status) {
                long size = MediaChooserConstants.ChekcMediaFileSize(new File(galleryModel.url.toString()),
                        true);
                if (size != 0) {
                    Toast.makeText(getActivity(),
                            getActivity().getResources().getString(R.string.file_size_exeeded) + "  "
                                    + MediaChooserConstants.SELECTED_VIDEO_SIZE_IN_MB + " "
                                    + getActivity().getResources().getString(R.string.mb),
                            Toast.LENGTH_SHORT).show();
                    return;
                }

                if (MediaChooserConstants.ENFORCE_VIDEO_DURATION_LIMIT && galleryModel
                        .getVideoDurationInSeconds() > MediaChooserConstants.VIDEO_DURATION_LIMIT_IN_SECOND) {
                    String fmt = getActivity().getResources().getString(R.string.video_duration_limit_exeeded);
                    String msg = String.format(fmt, MediaChooserConstants.VIDEO_DURATION_LIMIT_IN_SECOND);
                    Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT).show();
                    return;
                }

                if (MediaChooserConstants.MAX_MEDIA_LIMIT == 1) {
                    //remove all first
                    if (mSelectedModels.size() >= 1) {

                        MediaModel selModel = (MediaModel) mSelectedModels.get(0);
                        selModel.status = false;

                        mSelectedModels.clear();
                        MediaChooserConstants.SELECTED_MEDIA_COUNT--;
                    }
                }

                if ((MediaChooserConstants.MAX_MEDIA_LIMIT == MediaChooserConstants.SELECTED_MEDIA_COUNT)) {
                    if (MediaChooserConstants.SELECTED_MEDIA_COUNT < 2) {
                        Toast.makeText(getActivity(),
                                getActivity().getResources().getString(R.string.max_limit_file) + "  "
                                        + MediaChooserConstants.SELECTED_MEDIA_COUNT + " "
                                        + getActivity().getResources().getString(R.string.file),
                                Toast.LENGTH_SHORT).show();
                        return;
                    } else {
                        Toast.makeText(getActivity(),
                                getActivity().getResources().getString(R.string.max_limit_file) + "  "
                                        + MediaChooserConstants.SELECTED_MEDIA_COUNT + " "
                                        + getActivity().getResources().getString(R.string.files),
                                Toast.LENGTH_SHORT).show();
                        return;
                    }
                }
            }

            // inverse the status
            galleryModel.status = !galleryModel.status;
            adapter.notifyDataSetChanged();

            if (galleryModel.status) {
                mSelectedModels.add(galleryModel);

                MediaChooserConstants.SELECTED_MEDIA_COUNT++;

            } else {
                mSelectedModels.remove(galleryModel);

                MediaChooserConstants.SELECTED_MEDIA_COUNT--;
            }

            if (mCallback != null) {

                mCallback.onVideoSelectedCount(mSelectedModels.size());

                if (galleryModel.status) {
                    mCallback.onVideoSelected(galleryModel);
                } else {
                    mCallback.onVideoUnselected(galleryModel);
                }

                Intent intent = new Intent();
                intent.putParcelableArrayListExtra("selectedVideos", mSelectedModels);
                getActivity().setResult(Activity.RESULT_OK, intent);
            }

        }
    });

}

From source file:eu.basicairdata.graziano.gpslogger.FragmentTracklist.java

@Subscribe
public void onEvent(EventBusMSGNormal msg) {
    if (msg.MSGType == EventBusMSG.TRACKLIST_SELECTION) {
        final long selID = msg.id;
        if (selID >= 0) {
            getActivity().runOnUiThread(new Runnable() {
                @Override//from   w  w w .j a  v a  2 s . c o  m
                public void run() {
                    selectedtrackID = selID;
                    registerForContextMenu(view);
                    getActivity().openContextMenu(view);
                    unregisterForContextMenu(view);
                }
            });
        }
    }
    if (msg.MSGType == EventBusMSG.INTENT_SEND) {
        final long trackid = msg.id;
        if (trackid > 0) {
            Track track = GPSApplication.getInstance().GPSDataBase.getTrack(trackid);

            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_SEND_MULTIPLE);
            //intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.putExtra(Intent.EXTRA_SUBJECT, "GPS Logger - Track " + track.getName());

            PhysicalDataFormatter phdformatter = new PhysicalDataFormatter();
            PhysicalData phdDuration;
            PhysicalData phdSpeedMax;
            PhysicalData phdSpeedAvg;
            PhysicalData phdDistance;
            PhysicalData phdAltitudeGap;
            PhysicalData phdOverallDirection;
            phdDuration = phdformatter.format(track.getPrefTime(), PhysicalDataFormatter.FORMAT_DURATION);
            phdSpeedMax = phdformatter.format(track.getSpeedMax(), PhysicalDataFormatter.FORMAT_SPEED);
            phdSpeedAvg = phdformatter.format(track.getPrefSpeedAverage(),
                    PhysicalDataFormatter.FORMAT_SPEED_AVG);
            phdDistance = phdformatter.format(track.getEstimatedDistance(),
                    PhysicalDataFormatter.FORMAT_DISTANCE);
            phdAltitudeGap = phdformatter.format(
                    track.getEstimatedAltitudeGap(
                            GPSApplication.getInstance().getPrefEGM96AltitudeCorrection()),
                    PhysicalDataFormatter.FORMAT_ALTITUDE);
            phdOverallDirection = phdformatter.format(track.getBearing(), PhysicalDataFormatter.FORMAT_BEARING);
            if (track.getNumberOfLocations() <= 1) {
                intent.putExtra(Intent.EXTRA_TEXT,
                        (CharSequence) ("GPS Logger - Track " + track.getName() + "\n"
                                + track.getNumberOfLocations() + " " + getString(R.string.trackpoints) + "\n"
                                + track.getNumberOfPlacemarks() + " " + getString(R.string.placemarks)));
            } else {
                intent.putExtra(Intent.EXTRA_TEXT,
                        (CharSequence) ("GPS Logger - Track " + track.getName() + "\n"
                                + track.getNumberOfLocations() + " " + getString(R.string.trackpoints) + "\n"
                                + track.getNumberOfPlacemarks() + " " + getString(R.string.placemarks) + "\n"
                                + "\n" + getString(R.string.pref_track_stats) + " "
                                + (GPSApplication.getInstance().getPrefShowTrackStatsType() == 0
                                        ? getString(R.string.pref_track_stats_totaltime)
                                        : getString(R.string.pref_track_stats_movingtime))
                                + ":" + "\n" + getString(R.string.distance) + " = " + phdDistance.Value + " "
                                + phdDistance.UM + "\n" + getString(R.string.duration) + " = "
                                + phdDuration.Value + "\n" + getString(R.string.altitude_gap) + " = "
                                + phdAltitudeGap.Value + " " + phdAltitudeGap.UM + "\n"
                                + getString(R.string.max_speed) + " = " + phdSpeedMax.Value + " "
                                + phdSpeedMax.UM + "\n" + getString(R.string.average_speed) + " = "
                                + phdSpeedAvg.Value + " " + phdSpeedAvg.UM + "\n"
                                + getString(R.string.overall_direction) + " = " + phdOverallDirection.Value
                                + " " + phdOverallDirection.UM));
            }
            intent.setType("text/xml");

            ArrayList<Uri> files = new ArrayList<>();
            String fname = track.getName() + ".kml";
            File file = new File(Environment.getExternalStorageDirectory() + "/GPSLogger/AppData/", fname);
            if (file.exists() && GPSApplication.getInstance().getPrefExportKML()) {
                Uri uri = Uri.fromFile(file);
                files.add(uri);
            }
            fname = track.getName() + ".gpx";
            file = new File(Environment.getExternalStorageDirectory() + "/GPSLogger/AppData/", fname);
            if (file.exists() && GPSApplication.getInstance().getPrefExportGPX()) {
                Uri uri = Uri.fromFile(file);
                files.add(uri);
            }
            fname = track.getName() + ".txt";
            file = new File(Environment.getExternalStorageDirectory() + "/GPSLogger/AppData/", fname);
            if (file.exists() && GPSApplication.getInstance().getPrefExportTXT()) {
                Uri uri = Uri.fromFile(file);
                files.add(uri);
            }

            intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);

            String title = getString(R.string.card_menu_share);
            // Create intent to show chooser
            Intent chooser = Intent.createChooser(intent, title);

            // Verify the intent will resolve to at least one activity
            if ((intent.resolveActivity(getContext().getPackageManager()) != null) && (!files.isEmpty())) {
                startActivity(chooser);
            }
        }
    }
}

From source file:android.app.Activity.java

/**
 * Called when the activity is starting.  This is where most initialization
 * should go: calling {@link #setContentView(int)} to inflate the
 * activity's UI, using {@link #findViewById} to programmatically interact
 * with widgets in the UI, calling/*w ww.  ja  v  a  2 s. co  m*/
 * {@link #managedQuery(android.net.Uri , String[], String, String[], String)} to retrieve
 * cursors for data being displayed, etc.
 * 
 * <p>You can call {@link #finish} from within this function, in
 * which case onDestroy() will be immediately called without any of the rest
 * of the activity lifecycle ({@link #onStart}, {@link #onResume},
 * {@link #onPause}, etc) executing.
 * 
 * <p><em>Derived classes must call through to the super class's
 * implementation of this method.  If they do not, an exception will be
 * thrown.</em></p>
 * 
 * @param savedInstanceState If the activity is being re-initialized after
 *     previously being shut down then this Bundle contains the data it most
 *     recently supplied in {@link #onSaveInstanceState}.  <b><i>Note: Otherwise it is null.</i></b>
 * 
 * @see #onStart
 * @see #onSaveInstanceState
 * @see #onRestoreInstanceState
 * @see #onPostCreate
 */
protected void onCreate(Bundle savedInstanceState) {
    if (DEBUG_LIFECYCLE)
        Slog.v(TAG, "onCreate " + this + ": " + savedInstanceState);
    if (mLastNonConfigurationInstances != null) {
        mAllLoaderManagers = mLastNonConfigurationInstances.loaders;
    }
    if (mActivityInfo.parentActivityName != null) {
        if (mActionBar == null) {
            mEnableDefaultActionBarUp = true;
        } else {
            mActionBar.setDefaultDisplayHomeAsUpEnabled(true);
        }
    }

    if (isAvailable()) {
        /* if this device can use the platform */
        Log.w("MIGRATOR", "This is " + getLocalClassName());
        Intent intent = getIntent();
        Bundle tmpBundle = intent.getBundleExtra("MIGRATED");
        ArrayList<Bundle> stacked = intent.getParcelableArrayListExtra("MIGRATED STACK");
        if (tmpBundle != null) {
            /* true if this Activity was migrated */
            if (stacked != null) {
                /* true if this Activity called next Activity */
                Intent next = new Intent();
                Bundle nextBundle = stacked.get(0);
                next.setClassName(nextBundle.getString("MIGRATED PNAME"),
                        nextBundle.getString("MIGRATED CNAME"));
                next.putExtra("MIGRATED", nextBundle);
                stacked.remove(0);
                int code = tmpBundle.getInt("MIGRATED REQUEST CODE");
                Bundle option = nextBundle.getBundle("MIGRATED REQUEST OPTIONS");
                if (!stacked.isEmpty()) {
                    /* store for next Activity */
                    next.putParcelableArrayListExtra("MIGRATED STACK", stacked);
                }
                Log.w("MIGRATOR", "Start ForResult: code=" + code);
                mReceiverStackFlag = true;
                mStackedNextIntent = next;
                mStackedNextCode = code;
                mStackedNextOption = option;
            } else {
                /* for debug */
                Log.w("MIGRATOR", "stack is null");
            }
            savedInstanceState = null;
            mMigFlag = true;
            migratedState = tmpBundle;
            Intent tmpIntent = tmpBundle.getParcelable("MIGRATED_INTENT");
            if (tmpIntent != null) {
                tmpIntent.setAction(Intent.ACTION_MIGRATE);
                setIntent(tmpIntent);
            }

            /* File handling */
            ArrayList<String> tmpNames = tmpBundle.getStringArrayList("TARGET_FILE_NAME");
            if (tmpNames != null) {
                FileWorker fw = new FileWorker(tmpNames.toArray(new String[tmpNames.size()]),
                        FileWorker.WRITE_MODE);
                fw.start();
                tmpNames = null;
            }
            Log.w("MIGRATOR", "successed migaration: " + tmpBundle.toString());
            tmpBundle = null;
        } else {
            /* for debug */
            Log.w("MIGRATOR", "tmpBundle is null");
        }
    }

    if (savedInstanceState != null) {
        Parcelable p = savedInstanceState.getParcelable(FRAGMENTS_TAG);
        mFragments.restoreAllState(p,
                mLastNonConfigurationInstances != null ? mLastNonConfigurationInstances.fragments : null);
    }
    mFragments.dispatchCreate();
    getApplication().dispatchActivityCreated(this, savedInstanceState);
    mCalled = true;

}

From source file:com.diedrico.diedricoapp.PicMenuActivity.java

License:asdf

public ExpandableListView.OnChildClickListener onExpandableClick() { //Setup the listener to the expandable List View
    return new ExpandableListView.OnChildClickListener() {
        @Override/*w  ww.ja v a2  s  .c o m*/
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition,
                long id) {
            ArrayList<PointVector> pointVectors = new ArrayList<>();
            ArrayList<LineVector> lineVectors = new ArrayList<>();
            ArrayList<PlaneVector> planeVectors = new ArrayList<>();

            Intent intent = new Intent(context, MainActivity.class); //When we have the picture, we go to PreviewMenuActivity with the name of the file

            switch (groupPosition) {
            case 0:
                switch (childPosition) {
                case 0: //The user pressed welcome
                    intent.putExtra("title", R.string.welcome);
                    intent.putExtra("explanation", R.string.firtstext);
                    break;
                case 1: //the user pressed components of diedrico
                    intent.putExtra("title", R.string.components);
                    intent.putExtra("explanation", R.string.edges);
                    break;
                case 2: //the user pressed edges
                    intent.putExtra("title", R.string.edges);
                    intent.putExtra("explanation", R.string.firtstext);
                    break;
                }
                break;
            case 1:
                switch (childPosition) {
                case 0: //The user pressed point projection
                    pointVectors.add(new PointVector(0.75f, 0.25f, 0.0f));
                    pointVectors.add(new PointVector(0.4f, 0.6f, 0.0f));

                    intent.putExtra("title", R.string.pointProjection);
                    intent.putExtra("explanation", R.string.pointProjectionInfo);
                    break;
                case 1: ////The user pressed line projection
                    lineVectors.add(new LineVector(0.0f, 0.8f, 0.4f, 0.9f, 0.0f, -0.4f));

                    intent.putExtra("title", R.string.lineProjection);
                    intent.putExtra("explanation", R.string.lineProjectionInfo);
                    break;
                }
                break;
            case 2:
                switch (childPosition) {
                case 0: //the user pressed crosswideLine
                    lineVectors.add(new LineVector(0.0f, 0.8f, 0.4f, 0.9f, 0.0f, -0.4f));

                    intent.putExtra("title", R.string.crosswideLine);
                    intent.putExtra("explanation", R.string.crosswideLineInfo);
                    break;
                case 1: //the user pressed horizontal line
                    lineVectors.add(new LineVector(0.9f, 0.0f, 0.4f, 0.9f, 0.9f, -0.4f));

                    intent.putExtra("title", R.string.horizontalLine);
                    intent.putExtra("explanation", R.string.horizontalLineInfo);
                    break;
                case 2: //the user pressed frontal line
                    lineVectors.add(new LineVector(0.0f, 0.5f, 0.4f, 0.9f, 0.5f, -0.4f));

                    intent.putExtra("title", R.string.frontalLine);
                    intent.putExtra("explanation", R.string.frontalLineInfo);
                    break;
                case 3: //the user pressed rigid Line
                    lineVectors.add(new LineVector(0.5f, 0.0f, 0.0f, 0.5f, 0.9f, 0.0f));

                    intent.putExtra("title", R.string.rigidLine);
                    intent.putExtra("explanation", R.string.rigidLineInfo);
                    break;
                case 4: //the user pressed vertical lne
                    lineVectors.add(new LineVector(0.0f, 0.5f, 0.0f, 0.9f, 0.5f, 0.0f));

                    intent.putExtra("title", R.string.verticalLine);
                    intent.putExtra("explanation", R.string.verticalLineInfo);
                    break;
                case 5: //the user pressed ground line parallel line
                    lineVectors.add(new LineVector(0.5f, 0.5f, 0.4f, 0.5f, 0.5f, -0.4f));

                    intent.putExtra("title", R.string.groundLineParallelLine);
                    intent.putExtra("explanation", R.string.groundLineParallelLineInfo);
                    break;
                case 6: //the user pressed profileLine
                    lineVectors.add(new LineVector(0.9f, 0.0f, 0.0f, 0.0f, 0.9f, 0.0f));

                    intent.putExtra("title", R.string.profileLine);
                    intent.putExtra("explanation", R.string.profileLine);
                    break;
                case 7: //the user pressed ground line cutted line
                    lineVectors.add(new LineVector(0.0f, 0.0f, 0.0f, 0.9f, 0.9f, 0.0f));

                    intent.putExtra("title", R.string.groundLineCuttedLine);
                    intent.putExtra("explanation", R.string.groundLineCuttedLineInfo);
                    break;
                }
                break;
            case 3:
                switch (childPosition) {
                case 0: //the user pressed crosswide plane
                    planeVectors.add(new PlaneVector(new PointVector(0.0f, 0.0f, 0.4f),
                            new PointVector(0.0f, 1.0f, -0.5f), new PointVector(0.5f, 0.5f, -0.5f),
                            new PointVector(1.0f, 0.0f, -0.5f)));

                    intent.putExtra("title", R.string.crosswidePlane);
                    intent.putExtra("explanation", R.string.crosswidePlanoInfo);
                    break;
                case 1: //the user pressed horizontal plane
                    planeVectors.add(new PlaneVector(new PointVector(0.0f, 0.5f, -0.5f),
                            new PointVector(0.0f, 0.5f, 0.5f), new PointVector(0.9f, 0.5f, 0.5f),
                            new PointVector(0.9f, 0.5f, -0.5f)));

                    intent.putExtra("title", R.string.horizontalPlane);
                    intent.putExtra("explanation", R.string.horizontalPlaneInfo);
                    break;
                case 2: //the user pressed frontal plane
                    planeVectors.add(new PlaneVector(new PointVector(0.5f, 0.0f, 0.5f),
                            new PointVector(0.5f, 0.0f, -0.5f), new PointVector(0.5f, 1.0f, -0.5f),
                            new PointVector(0.5f, 1.0f, 0.5f)));

                    intent.putExtra("title", R.string.frontalPlane);
                    intent.putExtra("explanation", R.string.frontalPlaneInfo);
                    break;
                case 3: //the user pressed horizontal projection plane
                    planeVectors.add(new PlaneVector(new PointVector(0.0f, 1.0f, 0.4f),
                            new PointVector(0.0f, 0.0f, 0.4f), new PointVector(0.5f, 0.0f, -0.5f),
                            new PointVector(0.5f, 1.0f, -0.5f)));

                    intent.putExtra("title", R.string.horizontalProjectionPlane);
                    intent.putExtra("explanation", R.string.horizontalProjectionPlaneInfo);
                    break;
                case 4: //the user pressed vertical projection plane
                    planeVectors.add(new PlaneVector(new PointVector(0.0f, 0.0f, 0.4f),
                            new PointVector(0.0f, 1.0f, -0.5f), new PointVector(1.0f, 1.0f, -0.5f),
                            new PointVector(1.0f, 0.0f, 0.4f)));

                    intent.putExtra("title", R.string.verticalProjectionPlane);
                    intent.putExtra("explanation", R.string.verticalProjectionPlaneInfo);
                    break;
                case 5: //the user pressed groundLineParallelPlane
                    planeVectors.add(new PlaneVector(new PointVector(0.5f, 0.0f, 0.5f),
                            new PointVector(0.5f, 0.0f, -0.5f), new PointVector(0.0f, 0.7f, -0.5f),
                            new PointVector(0.0f, 0.7f, 0.5f)));

                    intent.putExtra("title", R.string.groundLineParallelPlane);
                    intent.putExtra("explanation", R.string.groundLineParallelPlaneInfo);
                    break;
                case 6: //the user pressed groundline cutted plane
                    planeVectors.add(new PlaneVector(new PointVector(0.0f, 0.0f, 0.5f),
                            new PointVector(1.0f, 1.0f, 0.5f), new PointVector(1.0f, 1.0f, -0.5f),
                            new PointVector(0.0f, 0.0f, -0.5f)));

                    intent.putExtra("title", R.string.groundLineCuttedPlane);
                    intent.putExtra("explanation", R.string.groundLineCuttedPlaneInfo);
                    break;
                case 7: //the user pressed profile plane
                    planeVectors.add(new PlaneVector(new PointVector(0.0f, 0.0f, 0.0f),
                            new PointVector(1.0f, 0.0f, 0.0f), new PointVector(1.0f, 1.0f, 0.0f),
                            new PointVector(0.0f, 1.0f, 0.0f)));

                    intent.putExtra("title", R.string.profilePlane);
                    intent.putExtra("explanation", R.string.profilePlaneInfo);
                    break;
                }
                break;
            }

            intent.putParcelableArrayListExtra("pointVectors", pointVectors);
            intent.putParcelableArrayListExtra("lineVectors", lineVectors);
            intent.putParcelableArrayListExtra("planeVectors", planeVectors);

            startActivity(intent);

            return false;
        }
    };
}

From source file:com.codename1.impl.android.AndroidImplementation.java

/**
 * @inheritDoc/*  w  w  w . j a  v a 2s .  c  o  m*/
 */
public void sendMessage(String[] recipients, String subject, Message msg) {
    if (editInProgress()) {
        stopEditing(true);
    }
    Intent emailIntent;
    String attachment = msg.getAttachment();
    boolean hasAttachment = (attachment != null && attachment.length() > 0) || msg.getAttachments().size() > 0;

    if (msg.getMimeType().equals(Message.MIME_TEXT) && !hasAttachment) {
        StringBuilder to = new StringBuilder();
        for (int i = 0; i < recipients.length; i++) {
            to.append(recipients[i]);
            to.append(";");
        }
        emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:" + to.toString() + "?subject="
                + Uri.encode(subject) + "&body=" + Uri.encode(msg.getContent())));
    } else {
        if (hasAttachment) {
            if (msg.getAttachments().size() > 1) {
                emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
                emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
                emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
                emailIntent.setType(msg.getMimeType());
                ArrayList<Uri> uris = new ArrayList<Uri>();

                for (String path : msg.getAttachments().keySet()) {
                    uris.add(Uri.parse(fixAttachmentPath(path)));
                }

                emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
            } else {
                emailIntent = new Intent(android.content.Intent.ACTION_SEND);
                emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
                emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
                emailIntent.setType(msg.getMimeType());
                emailIntent.setType(msg.getAttachmentMimeType());
                //if the attachment is in the uder home dir we need to copy it
                //to an accessible dir
                attachment = fixAttachmentPath(attachment);
                emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(attachment));
            }
        } else {
            emailIntent = new Intent(android.content.Intent.ACTION_SEND);
            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
            emailIntent.setType(msg.getMimeType());
        }
        if (msg.getMimeType().equals(Message.MIME_HTML)) {
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(msg.getContent()));
        } else {
            /*
            // Attempted this workaround to fix the ClassCastException that occurs on android when
            // there are multiple attachments.  Unfortunately, this fixes the stack trace, but
            // has the unwanted side-effect of producing a blank message body.
            // Same workaround for HTML mimetype also fails the same way.
            // Conclusion, Just live with the stack trace.  It doesn't seem to affect the
            // execution of the program... treat it as a warning.
            // See https://github.com/codenameone/CodenameOne/issues/1782
            if (msg.getAttachments().size() > 1) {
            ArrayList<String> contentArr = new ArrayList<String>();
            contentArr.add(msg.getContent());
            emailIntent.putStringArrayListExtra(android.content.Intent.EXTRA_TEXT, contentArr);
            } else {
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, msg.getContent());
                    
            }*/
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, msg.getContent());
        }

    }
    final String attach = attachment;
    AndroidNativeUtil.startActivityForResult(Intent.createChooser(emailIntent, "Send mail..."),
            new IntentResultListener() {

                @Override
                public void onActivityResult(int requestCode, int resultCode, Intent data) {
                    if (attach != null && attach.length() > 0 && attach.contains("tmp")) {
                        FileSystemStorage.getInstance().delete(attach);
                    }
                }
            });
}

From source file:com.zoffcc.applications.zanavi.Navit.java

void sendEmailWithAttachment(Context c, final String recipient, final String subject, final String message,
        final String full_file_name, final String full_file_name_suppl) {
    try {/*ww  w . j a  va  2  s  . co  m*/
        Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", recipient, null));
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
        ArrayList<Uri> uris = new ArrayList<>();
        uris.add(Uri.parse("file://" + full_file_name));
        try {
            if (new File(full_file_name_suppl).length() > 0) {
                uris.add(Uri.parse("file://" + full_file_name_suppl));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        List<ResolveInfo> resolveInfos = getPackageManager().queryIntentActivities(emailIntent, 0);
        List<LabeledIntent> intents = new ArrayList<>();

        if (resolveInfos.size() != 0) {
            for (ResolveInfo info : resolveInfos) {
                Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
                System.out.println(
                        "email:" + "comp=" + info.activityInfo.packageName + " " + info.activityInfo.name);
                intent.setComponent(new ComponentName(info.activityInfo.packageName, info.activityInfo.name));
                intent.putExtra(Intent.EXTRA_EMAIL, new String[] { recipient });
                if (subject != null)
                    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
                if (message != null)
                    intent.putExtra(Intent.EXTRA_TEXT, message);
                intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
                intents.add(new LabeledIntent(intent, info.activityInfo.packageName,
                        info.loadLabel(getPackageManager()), info.icon));
            }
            Intent chooser = Intent.createChooser(intents.remove(intents.size() - 1),
                    Navit.get_text("Send email with attachments"));
            chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, intents.toArray(new LabeledIntent[intents.size()]));
            startActivity(chooser);
        } else {
            System.out.println("email:" + "No Email App found");
            new AlertDialog.Builder(c).setMessage(Navit.get_text("No Email App found"))
                    .setPositiveButton(Navit.get_text("Ok"), null).show();
        }

        //         final Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", recipient, null));
        //         if (recipient != null) emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { recipient });
        //         if (subject != null) emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
        //         if (message != null) emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
        //         if (full_file_name != null)
        //         {
        //            emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + full_file_name));
        //            //ArrayList<Uri> uris = new ArrayList<>();
        //            //uris.add(Uri.parse("file://" + full_file_name));
        //            //emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); //ArrayList<Uri> of attachment Uri's
        //         }
        //
        //         List<ResolveInfo> resolveInfos = getPackageManager().queryIntentActivities(emailIntent, 0);
        //         if (resolveInfos.size() != 0)
        //         {
        //            String packageName = resolveInfos.get(0).activityInfo.packageName;
        //            String name = resolveInfos.get(0).activityInfo.name;
        //
        //            emailIntent.setAction(Intent.ACTION_SEND);
        //            emailIntent.setComponent(new ComponentName(packageName, name));
        //
        //            System.out.println("email:" + "comp=" + packageName + " " + name);
        //
        //            startActivity(emailIntent);
        //         }
        //         else
        //         {
        //            System.out.println("email:" + "No Email App found");
        //            new AlertDialog.Builder(c).setMessage(Navit.get_text("No Email App found")).setPositiveButton(Navit.get_text("Ok"), null).show();
        //         }

    } catch (ActivityNotFoundException e) {
        // cannot send email for some reason
    }
}