Example usage for android.content Intent hasExtra

List of usage examples for android.content Intent hasExtra

Introduction

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

Prototype

public boolean hasExtra(String name) 

Source Link

Document

Returns true if an extra value is associated with the given name.

Usage

From source file:com.example.nitish.welcomapp.activitypt.ElementDetailsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    final boolean darkTheme = PreferenceUtils.getPrefDarkTheme();
    setTheme(darkTheme ? R.style.DarkTheme : R.style.LightTheme);

    super.onCreate(savedInstanceState);

    ActionBarCompat.setDisplayHomeAsUpEnabled(this, true);

    if (savedInstanceState == null) {
        final Intent intent = getIntent();
        Fragment fragment = null;/*  w  ww  . j a  va 2s . com*/
        if (intent.hasExtra(EXTRA_ATOMIC_NUMBER)) {
            fragment = ElementDetailsFragment.getInstance(intent.getIntExtra(EXTRA_ATOMIC_NUMBER, 0));
        } else if (getIntent().getData() != null) {
            final Uri uri = getIntent().getData();
            if (uri.getHost().equals("element")) {
                final String path = uri.getPathSegments().get(0);
                if (TextUtils.isDigitsOnly(path)) {
                    try {
                        fragment = ElementDetailsFragment
                                .getInstance(Integer.parseInt(uri.getPathSegments().get(0)));
                    } catch (NumberFormatException e) {
                        Log.w(TAG, "Invalid atomic number");
                    }
                } else {
                    fragment = ElementDetailsFragment.getInstance(path);
                }
            }
        }
        if (fragment != null) {
            getSupportFragmentManager().beginTransaction().add(android.R.id.content, fragment).commit();
        }
    }
}

From source file:com.jesjimher.bicipalma.MapaActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mapa);/*  w w w  .j  av  a  2s. c  o m*/

    // Activar zoom
    GoogleMap mapa = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapfragment))
            .getMap();
    //        mapa.setBuiltInZoomControls(true);
    mapa.setMyLocationEnabled(true);

    // Si el mapa no est en Palma o similar, ponerlo en pza espaa
    CameraPosition c = mapa.getCameraPosition();
    Location actual = new Location("");
    actual.setLatitude(c.target.latitude);
    actual.setLongitude(c.target.longitude);
    Location pe = new Location("");
    pe.setLatitude(PZAESPANYA.latitude);
    pe.setLongitude(PZAESPANYA.longitude);
    if (actual.distanceTo(pe) >= 5000)
        mapa.moveCamera(CameraUpdateFactory.newLatLng(PZAESPANYA));

    Intent i = getIntent();
    //        GeoPoint point=null;
    if (i.hasExtra("estaciones")) {
        estaciones = i.getExtras().getParcelableArrayList("estaciones");

        for (Estacion e : estaciones) {
            LevelListDrawable d = (LevelListDrawable) getResources().getDrawable(R.drawable.estado_variable);
            d.setLevel(e.getBicisLibres() + 1);
            BitmapDrawable bd = (BitmapDrawable) d.getCurrent();
            Bitmap b = bd.getBitmap();
            Bitmap petit = Bitmap.createScaledBitmap(b, b.getWidth() / 2, b.getHeight() / 2, false);
            String mensaje = String.format("%s: %d, %s: %d", getResources().getString(R.string.lbicislibres),
                    e.getBicisLibres(), getResources().getString(R.string.lanclajeslibres),
                    e.getAnclajesLibres());
            mapa.addMarker(new MarkerOptions()
                    .position(new LatLng(e.getLoc().getLatitude(), e.getLoc().getLongitude()))
                    .title(e.getNombre()).snippet(mensaje).icon(BitmapDescriptorFactory.fromBitmap(petit)));
        }
        Double lat = i.getExtras().getDouble("latcentro");
        Double lon = i.getExtras().getDouble("longcentro");
        mapa.moveCamera(CameraUpdateFactory.zoomTo(16));
        mapa.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(lat, lon)));
    }
}

From source file:com.fastbootmobile.encore.app.SearchActivity.java

private void handleIntent(final Intent intent) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        if (!intent.hasExtra(SearchManager.QUERY)) {
            Toast.makeText(this, "Invalid search query: missing query", Toast.LENGTH_SHORT).show();
        } else {//w w w.ja  va  2s. co  m
            final String query = intent.getStringExtra(SearchManager.QUERY).trim();
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    mActiveFragment.resetResults();
                    mActiveFragment.setArguments(query);
                    ProviderAggregator.getDefault().startSearch(query);
                }
            }, 200);

            SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this,
                    SearchSuggestionProvider.AUTHORITY, SearchSuggestionProvider.MODE);
            suggestions.saveRecentQuery(query, null);
        }
    }
}

From source file:com.doctoror.fuckoffmusicplayer.presentation.media.MediaManagerService.java

private long getTargetId(@NonNull final Intent intent) {
    if (!intent.hasExtra(EXTRA_TARGET_ID)) {
        throw new IllegalArgumentException("EXTRA_TARGET_ID is not passed");
    }/*from w  ww  .  j av a2 s . c o  m*/

    return intent.getLongExtra(EXTRA_TARGET_ID, 0L);
}

From source file:ch.ethz.twimight.activities.UserListActivity.java

private void setInitialTab(Intent intent) {
    int initialPosition = 0;
    if (intent.hasExtra(EXTRA_KEY_INITIAL_TAB)) {
        String initialTab = intent.getStringExtra(EXTRA_KEY_INITIAL_TAB);

        if (EXTRA_INITIAL_TAB_FOLLOWING.equals(initialTab)) {
            initialPosition = 0;/*from www.  j  a  va  2  s. c o m*/
        } else if (EXTRA_INITIAL_TAB_FOLLOWERS.equals(initialTab)) {
            initialPosition = 1;
        } else if (EXTRA_INITIAL_TAB_PEERS.equals(initialTab)) {
            initialPosition = 2;
        }
        intent.removeExtra(EXTRA_KEY_INITIAL_TAB);
    }
    mViewPager.setCurrentItem(initialPosition);
}

From source file:com.example.android.aberdean.popularmoviesi.MovieDetails.java

/**
 * Assigns the appropriate values for the chosen movie.
 * @param savedInstanceState the previously saved state
 *//*from   w w w. ja v a2  s  .  c  o m*/
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.movie_details);

    mBackdrop = (ImageView) findViewById(R.id.iv_backdrop);
    mPosterThumb = (ImageView) findViewById(R.id.iv_poster_thumb);

    mSynopsis = (TextView) findViewById(R.id.tv_synopsis);
    mReleaseDate = (TextView) findViewById(R.id.tv_release_date);
    TextView mOriginalTitle = (TextView) findViewById(R.id.tv_title);
    mRating = (TextView) findViewById(R.id.tv_rating);

    Intent intent = getIntent();

    if (intent != null && intent.hasExtra("movieDetails")) {

        Resources res = getResources();

        ArrayList mChosenMovie = (ArrayList<?>) intent.getSerializableExtra("movieDetails");

        String posterUri = mChosenMovie.get(0).toString();
        String backdropUri = mChosenMovie.get(1).toString();
        setImage(posterUri, backdropUri);

        String synopsis = mChosenMovie.get(2).toString();
        mSynopsis.setText(synopsis);

        String releaseDate = mChosenMovie.get(3).toString();
        String release = String.format(res.getString(R.string.released), releaseDate);
        mReleaseDate.setText(release);

        String title = mChosenMovie.get(4).toString();
        mOriginalTitle.setText(title);

        String rating = mChosenMovie.get(5).toString();
        String rate = String.format(res.getString(R.string.rating), rating);
        mRating.setText(rate);
    }
}

From source file:com.digitallifelab.environmentmonitor.ImageDetailActivity.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/* ww  w .ja  va2s.c  om*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.image_detail_pager);

    // Fetch screen height and width, to use as our max size when loading images as this
    // activity runs full screen
    final DisplayMetrics displayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    final int height = displayMetrics.heightPixels;
    final int width = displayMetrics.widthPixels;

    Intent data = getIntent();
    if (data.hasExtra(IMAGES_ARRAY)) {
        imagesList = data.getStringArrayListExtra(IMAGES_ARRAY);
    } else {
        imagesList = new ArrayList<String>();
    }

    // Set up ViewPager and backing adapter
    mAdapter = new ImagePagerAdapter(getSupportFragmentManager(), imagesList.size());
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mAdapter);
    mPager.setPageMargin((int) getResources().getDimension(R.dimen.activity_horizontal_margin));
    mPager.setOffscreenPageLimit(2);

    // Set up activity to go full screen
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

    // Enable some additional newer visibility and ActionBar features to create a more
    // immersive photo viewing experience
    if (Utility.hasHoneycomb()) {
        //setSupportActionBar(null);
        final ActionBar actionBar = getSupportActionBar();

        // Hide title text and set home as up
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayHomeAsUpEnabled(true);

        // Hide and show the ActionBar as the visibility changes
        mPager.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int vis) {
                if ((vis & View.SYSTEM_UI_FLAG_LOW_PROFILE) != 0) {
                    actionBar.hide();
                } else {
                    actionBar.show();
                }
            }
        });

        // Start low profile mode and hide ActionBar
        mPager.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
        actionBar.hide();
    }

    // Set the current item based on the extra passed in to this activity
    final int extraCurrentItem = getIntent().getIntExtra(EXTRA_IMAGE, -1);
    if (extraCurrentItem != -1) {
        mPager.setCurrentItem(extraCurrentItem);
    }
}

From source file:eu.alefzero.owncloud.files.services.InstantUploadService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent == null || !intent.hasExtra(KEY_ACCOUNT) || !intent.hasExtra(KEY_DISPLAY_NAME)
            || !intent.hasExtra(KEY_FILE_PATH) || !intent.hasExtra(KEY_FILE_SIZE)
            || !intent.hasExtra(KEY_MIME_TYPE)) {
        Log.w(TAG, "Not all required information was provided, abording");
        return Service.START_NOT_STICKY;
    }//  w w w. j  a  va 2  s . c  o  m

    if (mUploaderRunnable == null) {
        mUploaderRunnable = new UploaderRunnable();
    }

    String filename = intent.getStringExtra(KEY_DISPLAY_NAME);
    String filepath = intent.getStringExtra(KEY_FILE_PATH);
    String mimetype = intent.getStringExtra(KEY_MIME_TYPE);
    Account account = intent.getParcelableExtra(KEY_ACCOUNT);
    long filesize = intent.getLongExtra(KEY_FILE_SIZE, -1);

    mUploaderRunnable.addElementToQueue(filename, filepath, mimetype, filesize, account);

    // starting new thread for new download doesnt seems like a good idea
    // maybe some thread pool or single background thread would be better
    Log.d(TAG, "Starting instant upload thread");
    new Thread(mUploaderRunnable).start();

    return Service.START_STICKY;
}

From source file:com.robwilliamson.healthyesther.dropbox.DropboxSyncActivity.java

@Override
protected synchronized void loadData() {
    if (!hasRequiredPermissions()) {
        return;//from  w ww.jav a 2  s.  com
    }

    setBusy(true);

    Boolean restore = false;

    Intent intent = getIntent();

    if (intent != null && intent.hasExtra(RESTORE)) {
        restore = intent.getBooleanExtra(RESTORE, false);
    }

    final Boolean backup = !restore;

    AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            try {
                if (backup) {
                    HealthDbHelper.getInstance().backupToDropbox();
                } else {
                    HealthDbHelper.getInstance().restoreFromDropbox();
                }
            } catch (IOException | DbxException e) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(DropboxSyncActivity.this, R.string.dropbox_sync_failed,
                                Toast.LENGTH_SHORT).show();
                    }
                });
                e.printStackTrace();
            } finally {
                setBusy(false);
                finish();
            }

            return null;
        }
    };
    task.execute();
}

From source file:com.example.android.popularmovies.activities.MovieDetailsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_movie_details);
    ButterKnife.bind(this);

    setSupportActionBar(mToolbar);//from  ww  w. j  a va2 s  . co m
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
    }

    mTabLayout.addTab(mTabLayout.newTab().setText(getString(R.string.details)));
    mTabLayout.addTab(mTabLayout.newTab().setText(getString(R.string.reviews)));
    mTabLayout.addTab(mTabLayout.newTab().setText(getString(R.string.trailers)));
    mTabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

    Intent intentThatStartedThisActivity = getIntent();
    if (intentThatStartedThisActivity.hasExtra(Movie.TAG)) {
        mMovie = intentThatStartedThisActivity.getParcelableExtra(Movie.TAG);
    }
    onRestore(intentThatStartedThisActivity.getExtras());

}