Example usage for android.content Intent getParcelableArrayListExtra

List of usage examples for android.content Intent getParcelableArrayListExtra

Introduction

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

Prototype

public <T extends Parcelable> ArrayList<T> getParcelableArrayListExtra(String name) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:com.keylesspalace.tusky.ViewMediaActivity.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_view_media);

    supportPostponeEnterTransition();/* www  .  j a  v  a2  s  .  com*/

    // Obtain the views.
    toolbar = findViewById(R.id.toolbar);
    viewPager = findViewById(R.id.view_pager);
    anyView = toolbar;

    // Gather the parameters.
    Intent intent = getIntent();
    attachments = intent.getParcelableArrayListExtra(EXTRA_ATTACHMENTS);
    int initialPosition = intent.getIntExtra(EXTRA_ATTACHMENT_INDEX, 0);

    final PagerAdapter adapter;

    if (attachments != null) {
        List<Attachment> realAttachs = CollectionsKt.map(attachments, AttachmentViewData::getAttachment);
        // Setup the view pager.
        adapter = new ImagePagerAdapter(getSupportFragmentManager(), realAttachs, initialPosition);

    } else {
        String avatarUrl = intent.getStringExtra(EXTRA_AVATAR_URL);

        if (avatarUrl == null) {
            throw new IllegalArgumentException("attachment list or avatar url has to be set");
        }

        adapter = new AvatarImagePagerAdapter(getSupportFragmentManager(), avatarUrl);
    }

    viewPager.setAdapter(adapter);
    viewPager.setCurrentItem(initialPosition);
    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            CharSequence title = adapter.getPageTitle(position);
            toolbar.setTitle(title);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });

    // Setup the toolbar.
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowHomeEnabled(true);
        actionBar.setTitle(adapter.getPageTitle(initialPosition));
    }
    toolbar.setNavigationOnClickListener(v -> supportFinishAfterTransition());
    toolbar.setOnMenuItemClickListener(item -> {
        int id = item.getItemId();
        switch (id) {
        case R.id.action_download:
            downloadImage();
            break;
        case R.id.action_open_status:
            onOpenStatus();
            break;
        }
        return true;
    });

    View decorView = getWindow().getDecorView();
    int uiOptions = View.SYSTEM_UI_FLAG_LOW_PROFILE;
    decorView.setSystemUiVisibility(uiOptions);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().setStatusBarColor(Color.BLACK);
    }
}

From source file:am.roadpolice.roadpolice.ViolationInfoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_violation_info);

    DialogRateUs.showRateUs(getApplicationContext(), getSupportFragmentManager());

    // Customize Action Bar
    ActionBar actionBar = getSupportActionBar();
    actionBar.setBackgroundDrawable(new ColorDrawable(0xFF1A237E));
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setTitle(Html.fromHtml("<small>" + getString(R.string.title_activity_info) + "</small>"));

    final Intent intent = getIntent();
    // Get Data which is sent from MainActivity.
    mAutoLogin = intent.getBooleanExtra(EXTRA_AUTO_LOGIN, false);
    ArrayList<ViolationInfo> violationList = intent.getParcelableArrayListExtra(EXTRA_VIOLATION_INFO_LIST);

    ViolationInfoAdapter adapter = new ViolationInfoAdapter(getApplicationContext(), violationList);

    ListView listView = (ListView) findViewById(R.id.listViewViolationInfo);
    listView.setOnItemClickListener(this);
    listView.setEmptyView(findViewById(R.id.textViewEmpty));
    listView.setAdapter(adapter);//from   ww  w . j  a  va  2  s  .c  o  m
}

From source file:gc.david.dfm.ui.activity.ShowInfoActivity.java

private void getIntentData() {
    DFMLogger.logMessage(TAG, "getIntentData");

    final Intent inputDataIntent = getIntent();
    positionsList = inputDataIntent.getParcelableArrayListExtra(POSITIONS_LIST_EXTRA_KEY);
    distance = inputDataIntent.getStringExtra(DISTANCE_EXTRA_KEY);
}

From source file:com.krayzk9s.imgurholo.services.DownloadService.java

@Override
protected void onHandleIntent(Intent intent) {
    final NotificationManager notificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    ids = intent.getParcelableArrayListExtra("ids");
    albumName = "/";
    downloaded = 0;/* w w w. j  a  v  a  2 s.  c  o m*/
    if (ids.size() > 0) {
        albumName += intent.getStringExtra("albumName") + "/";
        File myDirectory = new File(
                android.os.Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
                albumName);
        if (!myDirectory.exists()) {
            myDirectory.mkdirs();
        }
    }
    for (int i = 0; i < ids.size(); i++) {
        try {
            final String type = ids.get(i).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TYPE)
                    .split("/")[1];
            final String id = ids.get(i).getJSONObject().getString("id");
            final String link = ids.get(i).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK);
            Log.d("data", ids.get(i).getJSONObject().toString());
            Log.d(ImgurHoloActivity.IMAGE_DATA_TYPE,
                    ids.get(0).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TYPE).split("/")[1]);
            Log.d("id", ids.get(i).getJSONObject().getString("id"));
            Log.d(ImgurHoloActivity.IMAGE_DATA_LINK,
                    ids.get(0).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK));
            final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
            notificationBuilder.setContentTitle(getString(R.string.picture_download))
                    .setContentText(getString(R.string.download_in_progress))
                    .setSmallIcon(R.drawable.icon_desaturated);
            Ion.with(getApplicationContext(), link).progress(new ProgressCallback() {
                @Override
                public void onProgress(int i, int i2) {
                    notificationBuilder.setProgress(i2, i, false);
                }
            }).write(new File(
                    android.os.Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
                            + albumName + id + "." + type))
                    .setCallback(new FutureCallback<File>() {
                        @Override
                        public void onCompleted(Exception e, File file) {
                            if (file == null)
                                return;
                            downloaded += 1;
                            if (downloaded == ids.size()) {
                                NotificationCompat.Builder notificationComplete = new NotificationCompat.Builder(
                                        getApplicationContext());
                                if (ids.size() == 1) {
                                    Intent viewImageIntent = new Intent(Intent.ACTION_VIEW);
                                    viewImageIntent.setDataAndType(Uri.fromFile(file), "image/*");
                                    Intent shareIntent = new Intent(Intent.ACTION_SEND);
                                    shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                                    shareIntent.setType("image/*");
                                    shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
                                    PendingIntent viewImagePendingIntent = PendingIntent.getActivity(
                                            getApplicationContext(), (int) System.currentTimeMillis(),
                                            viewImageIntent, 0);
                                    PendingIntent sharePendingIntent = PendingIntent.getActivity(
                                            getApplicationContext(), (int) System.currentTimeMillis(),
                                            shareIntent, 0);
                                    notificationComplete.setContentTitle(getString(R.string.download_complete))
                                            .setSmallIcon(R.drawable.icon_desaturated)
                                            .setContentText(String.format(getString(R.string.download_progress),
                                                    downloaded))
                                            .setContentIntent(viewImagePendingIntent)
                                            .addAction(R.drawable.dark_social_share, getString(R.string.share),
                                                    sharePendingIntent);
                                } else {
                                    Intent i = new Intent(Intent.ACTION_PICK);
                                    i.setDataAndType(
                                            Uri.fromFile(new File(
                                                    android.os.Environment.getExternalStoragePublicDirectory(
                                                            Environment.DIRECTORY_PICTURES) + albumName)),
                                            "image/*");
                                    PendingIntent viewImagePendingIntent = PendingIntent.getActivity(
                                            getApplicationContext(), (int) System.currentTimeMillis(), i, 0);
                                    notificationComplete.setContentTitle(getString(R.string.download_complete))
                                            .setSmallIcon(R.drawable.icon_desaturated).setContentText(String
                                                    .format(getString(R.string.download_progress), downloaded))
                                            .setContentIntent(viewImagePendingIntent);
                                }
                                notificationManager.cancel(0);
                                notificationManager.cancel(1);
                                notificationManager.notify(1, notificationComplete.build());
                            }
                            MediaScannerConnection.scanFile(getApplicationContext(),
                                    new String[] { android.os.Environment.getExternalStoragePublicDirectory(
                                            Environment.DIRECTORY_PICTURES) + albumName + id + "." + type },
                                    null, new MediaScannerConnection.OnScanCompletedListener() {
                                        @Override
                                        public void onScanCompleted(final String path, final Uri uri) {
                                            Log.i("Scanning", String.format("Scanned path %s -> URI = %s", path,
                                                    uri.toString()));
                                        }
                                    });
                        }
                    });
            notificationManager.notify(0, notificationBuilder.build());
        } catch (JSONException e) {
            Log.e("Error!", e.toString());
        }
    }
}

From source file:com.example.android.activityrecognition.CreateMapActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.basic_demo);

    mMarkerPoints = new ArrayList<LatLng>();

    /**/*from  w  ww  .  ja va2s  .c  o  m*/
     * Intent to capture coordinates of Car and User location send by Main
     * activity
     */
    Intent intent = getIntent();

    mMarkerPoints = intent.getParcelableArrayListExtra(ACTIVITY_SERVICE);

    // Create the map if map doesn't exists
    setUpMapIfNeeded();
}

From source file:info.tongrenlu.FullScreenPlayerActivity.java

private void updateFromService(Intent intent) {
    Log.d(TAG, "updateMedia called ");

    List<TrackBean> trackList = intent.getParcelableArrayListExtra(MusicService.PARAM_TRACK_LIST);
    int position = intent.getIntExtra(MusicService.PARAM_POSITION, 0);
    TrackBean trackBean = trackList.get(position);

    final ActionBar ab = getSupportActionBar();
    if (ab != null) {
        ab.setDisplayHomeAsUpEnabled(true);
    }//from w  w w .  ja v a2 s .  c o m

    String title = trackBean.getName();
    mLine1.setText(title);

    mCurrentArtUri = Uri.parse("http://files.tongrenlu.info/m" + trackBean.getArticleId() + "/cover_400.jpg");
    Glide.with(getApplicationContext()).load(mCurrentArtUri).into(mBackgroundImage);

    int duration = intent.getIntExtra(MusicService.PARAM_DURATION, 0);
    mSeekbar.setMax(duration);
    mEnd.setText(toTime(duration));
}

From source file:cw89.cwgallerydemo.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);

    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == Config.INTENT_REQUEST_CWGALLERY) {

            list = intent.getParcelableArrayListExtra(Config.INTENT_RESULT_NAME);

            if (list != null) {
                updateImage();/*  w w w .  j a va2  s.com*/
                updateData();
            }

        }
    }
}

From source file:com.liferay.alerts.activity.CommentsActivity.java

private void _registerBroadcastReceiver() {
    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_ADD_COMMENT);
    filter.addAction(ACTION_UPDATE_COMMENTS_LIST);

    _receiver = new BroadcastReceiver() {

        @Override//from  w  w w .j a v a  2s  .  c  o  m
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            ListView listView = (ListView) findViewById(R.id.comments);

            if (ACTION_UPDATE_COMMENTS_LIST.equals(action)) {
                ArrayList<Alert> alerts = intent.getParcelableArrayListExtra(EXTRA_ALERTS);

                ArrayAdapter<Alert> adapter = new CommentListAdapter(getApplicationContext(), alerts);

                listView.setAdapter(adapter);
            } else if (ACTION_ADD_COMMENT.equals(action)) {
                Alert alert = intent.getParcelableExtra(EXTRA_ALERT);

                ArrayAdapter<Alert> adapter = (ArrayAdapter<Alert>) listView.getAdapter();

                adapter.add(alert);
            }
        }

    };

    _getBroadcastManager().registerReceiver(_receiver, filter);
}

From source file:com.android.contacts.SimImportService.java

private ImportTask createTaskForIntent(Intent intent, int startId) {
    final AccountWithDataSet targetAccount = intent.getParcelableExtra(EXTRA_ACCOUNT);
    final ArrayList<SimContact> contacts = intent.getParcelableArrayListExtra(EXTRA_SIM_CONTACTS);

    final int subscriptionId = intent.getIntExtra(EXTRA_SIM_SUBSCRIPTION_ID, SimCard.NO_SUBSCRIPTION_ID);
    final SimContactDao dao = SimContactDao.create(this);
    final SimCard sim = dao.getSimBySubscriptionId(subscriptionId);
    if (sim != null) {
        return new ImportTask(sim, contacts, targetAccount, dao, startId);
    } else {/*from w  ww. j  a  v a  2  s.  c o  m*/
        return null;
    }
}

From source file:com.germainz.identiconizer.services.IdenticonRemovalService.java

@Override
protected void onHandleIntent(Intent intent) {
    startForeground(SERVICE_NOTIFICATION_ID, createNotification());
    // If a predefined contacts list is provided, use it directly.
    // contactsList is set when this service is started from ContactsListActivity.
    if (intent.hasExtra("contactsList")) {
        ArrayList<ContactInfo> contactsList = intent.getParcelableArrayListExtra("contactsList");
        processPhotos(contactsList);//from  w  ww .jav  a  2 s.  com
    } else {
        processPhotos();
    }
    LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent("CONTACTS_UPDATED"));
    stopForeground(true);
}