List of usage examples for android.os Bundle getParcelable
@Nullable public <T extends Parcelable> T getParcelable(@Nullable String key)
From source file:com.abc.driver.TruckActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == CellSiteConstants.TAKE_PICTURE || requestCode == CellSiteConstants.PICK_PICTURE) { Uri uri = null;// w w w .j av a 2 s . co m if (requestCode == CellSiteConstants.TAKE_PICTURE) { uri = imageUri; } else if (requestCode == CellSiteConstants.PICK_PICTURE) { uri = data.getData(); } String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(uri, filePathColumn, null, null, null); if (cursor != null && cursor.moveToFirst()) { int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String filePath = cursor.getString(columnIndex); cursor.close(); Log.d(TAG, "filePath =" + filePath); Log.d(TAG, "uri=" + uri.toString()); imageUri = Uri.fromFile(new File(filePath)); } else // { if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { Toast.makeText(this, R.string.sdcard_occupied, Toast.LENGTH_SHORT).show(); return; } String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File tmpFile = new File(app.regUserPath + File.separator + "IMG_" + timeStamp + ".png"); File srcFile = new File(uri.getPath()); if (srcFile.exists()) { try { Utils.copyFile(srcFile, tmpFile); app.getUser().getMyTruck().setLicenseImageUrl(tmpFile.getAbsolutePath()); } catch (Exception e) { Toast.makeText(this, R.string.create_tmp_file_fail, Toast.LENGTH_SHORT).show(); return; } } else { Log.d(TAG, "Logic error, should not come to here"); Toast.makeText(this, R.string.file_not_found, Toast.LENGTH_SHORT).show(); return; } imageUri = Uri.fromFile(tmpFile); } // doCrop(); Bitmap tmpBmp = BitmapFactory.decodeFile(imageUri.getPath(), null); Bitmap scaledBmp = Bitmap.createScaledBitmap(tmpBmp, IMAGE_WIDTH, IMAGE_HEIGHT, false); mTLPiv.setImageBitmap(scaledBmp); isPortraitChanged = true; Log.d(TAG, "onActivityResult PICK_PICTURE"); mUpdateImageTask = new UpdateImageTask(); mUpdateImageTask.execute("" + app.getUser().getId(), "" + app.getUser().getMyTruck().getTruckId(), Utils.bitmap2String(scaledBmp), CellSiteConstants.UPDATE_TRUCK_LICENSE_URL); } else if (requestCode == CellSiteConstants.CROP_PICTURE) { Log.d(TAG, "crop picture"); // processFile(); if (data != null) { Bundle extras = data.getExtras(); Bitmap photo = extras.getParcelable("data"); trcukLicenseBmp = photo; mTLPiv.setImageBitmap(trcukLicenseBmp); mUpdateImageTask = new UpdateImageTask(); mUpdateImageTask.execute("" + app.getUser().getId(), "" + app.getUser().getMyTruck().getTruckId(), Utils.bitmap2String(trcukLicenseBmp), CellSiteConstants.UPDATE_DRIVER_LICENSE_URL); isPortraitChanged = true; } } else if (requestCode == CellSiteConstants.TAKE_PICTURE2 || requestCode == CellSiteConstants.PICK_PICTURE2) { Uri uri = null; if (requestCode == CellSiteConstants.TAKE_PICTURE2) { uri = imageUri; } else if (requestCode == CellSiteConstants.PICK_PICTURE2) { uri = data.getData(); } String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(uri, filePathColumn, null, null, null); if (cursor != null && cursor.moveToFirst()) { int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String filePath = cursor.getString(columnIndex); cursor.close(); Log.d(TAG, "filePath =" + filePath); Log.d(TAG, "uri=" + uri.toString()); imageUri = Uri.fromFile(new File(filePath)); } else // { if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { Toast.makeText(this, R.string.sdcard_occupied, Toast.LENGTH_SHORT).show(); return; } String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File tmpFile = new File(app.regUserPath + File.separator + "IMG_" + timeStamp + ".png"); File srcFile = new File(uri.getPath()); if (srcFile.exists()) { try { Utils.copyFile(srcFile, tmpFile); app.getUser().getMyTruck().setPhotoImageUrl(tmpFile.getAbsolutePath()); } catch (Exception e) { Toast.makeText(this, R.string.create_tmp_file_fail, Toast.LENGTH_SHORT).show(); return; } } else { Log.d(TAG, "Logic error, should not come to here"); Toast.makeText(this, R.string.file_not_found, Toast.LENGTH_SHORT).show(); return; } imageUri = Uri.fromFile(tmpFile); } // doCrop(); Bitmap tmpBmp = BitmapFactory.decodeFile(imageUri.getPath(), null); Bitmap scaledBmp = Bitmap.createScaledBitmap(tmpBmp, IMAGE_WIDTH, IMAGE_HEIGHT, false); mTPiv.setImageBitmap(scaledBmp); // s isChanged = true; mUpdateImageTask = new UpdateImageTask(); mUpdateImageTask.execute("" + app.getUser().getId(), "" + app.getUser().getMyTruck().getTruckId(), Utils.bitmap2String(scaledBmp), CellSiteConstants.UPDATE_TRUCK_PHOTO_URL); } else if (requestCode == CellSiteConstants.UPDATE_TRUCK_MOBILE_REQUSET) { Log.d(TAG, "mobile changed"); if (app.getUser().getMyTruck().getMobileNum() == null) { mTMtv.setText(app.getUser().getMobileNum()); app.getUser().getMyTruck().setMobileNum(app.getUser().getMobileNum()); } else { mTMtv.setText(app.getUser().getMyTruck().getMobileNum()); } } }
From source file:no.nordicsemi.android.nrftoolbox.dfu.DfuActivity.java
@Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { if (resultCode != RESULT_OK) return;//from w w w . j av a 2 s. c om switch (requestCode) { case SELECT_FILE_REQ: // clear previous data mFilePath = null; mFileStreamUri = null; // and read new one final Uri uri = data.getData(); /* * The URI returned from application may be in 'file' or 'content' schema. * 'File' schema allows us to create a File object and read details from if directly. * * Data from 'Content' schema must be read by Content Provider. To do that we are using a Loader. */ if (uri.getScheme().equals("file")) { // the direct path to the file has been returned final String path = uri.getPath(); final File file = new File(path); mFilePath = path; mFileNameView.setText(file.getName()); mFileSizeView.setText(getString(R.string.dfu_file_size_text, file.length())); final boolean isHexFile = mStatusOk = MimeTypeMap.getFileExtensionFromUrl(path) .equalsIgnoreCase("HEX"); mFileStatusView.setText(isHexFile ? R.string.dfu_file_status_ok : R.string.dfu_file_status_invalid); mUploadButton.setEnabled(mSelectedDevice != null && isHexFile); } else if (uri.getScheme().equals("content")) { // an Uri has been returned mFileStreamUri = uri; // if application returned Uri for streaming, let's us it. Does it works? // FIXME both Uris works with Google Drive app. Why both? What's the difference? How about other apps like DropBox? final Bundle extras = data.getExtras(); if (extras != null && extras.containsKey(Intent.EXTRA_STREAM)) mFileStreamUri = extras.getParcelable(Intent.EXTRA_STREAM); // file name and size must be obtained from Content Provider final Bundle bundle = new Bundle(); bundle.putParcelable(EXTRA_URI, uri); getSupportLoaderManager().restartLoader(0, bundle, this); } break; default: break; } }
From source file:com.armannds.eldgos.katla.popularmovies.ui.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); ((PopularMoviesApplication) getApplication()).getNetworkComponent().inject(this); Context context = this; MoviesAdapter.MoviesAdapterOnClickHandler clickHandler = this; mMoviesAdapter = new MoviesAdapter(context, clickHandler); mRecyclerView.setAdapter(mMoviesAdapter); mRecyclerView.setLayoutManager(new GridLayoutManager(this, calculateNoOfColumns())); mRecyclerView.setHasFixedSize(true); if (isSavedInstanceStateValid(savedInstanceState)) { List<Movie> movies = Parcels.unwrap(savedInstanceState.getParcelable(mMoviesKey)); mMoviesAdapter.setMovies(movies); String title = savedInstanceState.getString(mTitleKey); setTitle(title);//from w ww . ja v a2 s. com } else { if (isOnline()) { loadMovies(R.string.popular); } else { showErrorMessage(); } } }
From source file:org.dvbviewer.controller.ui.fragments.ChannelEpg.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setLayoutRessource(R.layout.fragment_channel_epg); mImageCacher = new ImageCacher(getActivity()); if (savedInstanceState != null && savedInstanceState.containsKey(Channel.class.getName())) { mCHannel = savedInstanceState.getParcelable(Channel.class.getName()); }/* ww w . j av a 2 s .c o m*/ }
From source file:com.notalenthack.blaster.CommandActivity.java
/** * Called when the activity is first created. *//*w w w .j a v a 2 s . c om*/ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mThisActivity = this; final Intent launchingIntent = getIntent(); // Retrieve the Query Type and Position from the intent or bundle if (savedInstanceState != null) { mDevice = savedInstanceState.getParcelable(Constants.KEY_DEVICE_STATE); } else if (launchingIntent != null) { mDevice = launchingIntent.getParcelableExtra(Constants.KEY_DEVICE_STATE); } setContentView(R.layout.commands); // get the fields mModelName = (TextView) findViewById(R.id.modelName); mCores = (TextView) findViewById(R.id.cores); mCacheSize = (TextView) findViewById(R.id.cacheSize); mConnectStatus = (TextView) findViewById(R.id.status); mDeviceStatus = (ImageView) findViewById(R.id.deviceStatusIcon); mBatteryStatus = (ImageView) findViewById(R.id.batteryStatus); mCmdListView = (ListView) findViewById(R.id.listView); ; mBtnExecAll = (Button) findViewById(R.id.btnExecAll); if (mDevice != null) { getActionBar().setHomeButtonEnabled(true); getActionBar().setIcon(R.drawable.ic_action_navigation_previous_item); mSerialService = new BluetoothSerialService(this, mHandlerBT); mSerialService.connect(mDevice.getBluetoothDevice()); // Execute all the commands mBtnExecAll.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // do a quick status update on the commands List<Command> commands = mListAdapter.getCommands(); // this list should be in the same order as in the ListBox for (Command cmd : commands) { if (cmd.getCommandStart().equalsIgnoreCase(Command.LAUNCHER_START)) { launchCommand(cmd); } else if (!cmd.getCommandStart().equalsIgnoreCase(Command.OBEX_FTP_START)) { executeCommand(cmd); } } } }); setupCommandList(); } else { Log.e(TAG, "Bluetooth device is not initialized"); finish(); } }
From source file:com.appsimobile.appsii.module.apps.ReorderAppsFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); AppInjector.inject(this); // create the adapter here to make sure we can set it's data and register it's listener // This ensures the life cycles are the same mAppsAdapter = new AppsAdapter(); // now get the tag we need to display the data from if (savedInstanceState != null) { mAppTag = savedInstanceState.getParcelable("tag"); }//from w w w.j av a2 s . c om // see if the retain fragment is already present. Otherwise create it. // the key has to be unique because multiple pages may be added by the pager. String key = "retain"; mRetainFragment = (RetainQueryHelperFragment) getFragmentManager().findFragmentByTag(key); // when the fragment was null, create it and add it. if (mRetainFragment == null) { mRetainFragment = new RetainQueryHelperFragment(); getFragmentManager().beginTransaction().add(mRetainFragment, key).commit(); } // now that the fragment is added, initialize the loader. getLoaderManager().initLoader(100, null, new AllAppsLoaderCallbacks()); if (mAppTag != null) { mRetainFragment.loadTaggedApps(mAppTag.id); } }
From source file:com.cuddlesoft.nori.ImageViewerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Get shared preferences. sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); // Get data out of Intent sent by SearchActivity or restore them from the saved instance // state.//from www . j a v a 2s. c o m int imageIndex; if (savedInstanceState != null && savedInstanceState.containsKey(BUNDLE_ID_IMAGE_INDEX) && savedInstanceState.containsKey(BUNDLE_ID_SEARCH_RESULT)) { imageIndex = savedInstanceState.getInt(BUNDLE_ID_IMAGE_INDEX); searchResult = savedInstanceState.getParcelable(BUNDLE_ID_SEARCH_RESULT); searchClient = ((SearchClient.Settings) savedInstanceState .getParcelable(BUNDLE_ID_SEARCH_CLIENT_SETTINGS)).createSearchClient(); } else { final Intent intent = getIntent(); imageIndex = intent.getIntExtra(SearchActivity.BUNDLE_ID_IMAGE_INDEX, 0); searchResult = intent.getParcelableExtra(SearchActivity.BUNDLE_ID_SEARCH_RESULT); searchClient = ((SearchClient.Settings) intent .getParcelableExtra(SearchActivity.BUNDLE_ID_SEARCH_CLIENT_SETTINGS)).createSearchClient(); } // Request window features. supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); // Keep screen on, if enabled by the user. if (sharedPreferences.getBoolean(getString(R.string.preference_image_viewer_keepScreenOn_key), true)) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } // Populate content view. setContentView(R.layout.activity_image_viewer); // Set up the action bar. final ActionBar actionBar = getSupportActionBar(); actionBar.hide(); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayHomeAsUpEnabled(true); // Create and set the image viewer Fragment pager adapter. imagePagerAdapter = new ImagePagerAdapter(getSupportFragmentManager()); viewPager = (ImageViewerPager) findViewById(R.id.image_pager); viewPager.setAdapter(imagePagerAdapter); viewPager.setOnPageChangeListener(this); viewPager.setCurrentItem(imageIndex); // Set up the GestureDetector used to toggle the action bar. gestureDetector = new GestureDetector(this, gestureListener); viewPager.setOnMotionEventListener(this); // Set activity title. setTitle(searchResult.getImages()[imageIndex]); // Dim system UI. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { viewPager.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE); } }
From source file:ca.marklauman.dominionpicker.SupplyActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_supply); getSupportActionBar().setDisplayHomeAsUpEnabled(true); ListView card_list = (ListView) findViewById(R.id.card_list); View loading = findViewById(android.R.id.progress); card_list.setEmptyView(loading);/* w ww .j av a2 s. c om*/ resView = (TextView) findViewById(R.id.resources); resView.setVisibility(View.GONE); // Setup the adapter adapter = new CardAdapter(this); adapter.changeCursor(null); card_list.setAdapter(adapter); // Restore the supply if this is a restore supply = null; if (savedInstanceState != null) { Supply supply = savedInstanceState.getParcelable(KEY_SUPPLY); if (supply != null) setSupply(supply); } else { // No supply? Shuffle one! SupplyShuffler shuffler = new SupplyShuffler(this); // Pool must be passed as type Long not long long[] cards = getIntent().getExtras().getLongArray(PARAM_CARDS); Long[] pool = new Long[cards.length]; for (int i = 0; i < cards.length; i++) pool[i] = cards[i]; shuffler.execute(pool); } }
From source file:bottombar.BottomBar.java
@Override public void onRestoreInstanceState(Parcelable state) { if (state instanceof Bundle) { Bundle bundle = (Bundle) state; restoreState(bundle);// w w w .ja v a 2 s . com state = bundle.getParcelable("superstate"); } super.onRestoreInstanceState(state); }
From source file:com.richtodd.android.quiltdesign.app.BlockEditActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_block_edit); getActionBar().setDisplayHomeAsUpEnabled(true); m_blockNameArgument = getIntent().getStringExtra(ARG_BLOCK_NAME); if (savedInstanceState != null) { m_saveAsBlockName = savedInstanceState.getString("saveAsBlockName"); m_theme = (Theme) savedInstanceState.getParcelable("theme"); }/*from w ww .j a v a 2 s .co m*/ ActionBar ab = getActionBar(); ab.setTitle("Edit Block"); ab.setSubtitle(getCurrentBlockName()); FragmentManager fm = getFragmentManager(); // Create color settings fragment. { Fragment f = fm.findFragmentById(R.id.layout_blockEditFragment); if (f == null) { f = BlockEditFragment.create(m_blockNameArgument); fm.beginTransaction().add(R.id.layout_blockEditFragment, f).commit(); } } m_themeView = (ThemeView) findViewById(R.id.themeView); m_themeView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Swatch swatch = (Swatch) m_themeView.getItemAtPosition(position); BlockEditFragment fragment = getBlockEditFragment(); if (fragment != null) { fragment.setColor(swatch.getColor()); } } }); m_themeView.setTheme(m_theme); m_button_setColor = (Button) findViewById(R.id.button_setColor); m_button_setColor.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { chooseColor(); } }); m_button_addPiece = (Button) findViewById(R.id.button_addPiece); m_button_addPiece.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { BlockEditFragment fragment = getBlockEditFragment(); int color = fragment.getColor(); PaperPiecedBlockPiece piece = fragment.addPiece(color); onPieceSelected(fragment, piece); } }); m_button_deletePiece = (Button) findViewById(R.id.button_deletePiece); m_button_deletePiece.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { BlockEditFragment fragment = getBlockEditFragment(); fragment.deletePiece(); onPieceSelected(fragment, null); } }); ImageView button_refreshTheme = (ImageView) findViewById(R.id.button_refreshTheme); button_refreshTheme.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { refreshTheme(); } }); ImageView button_selectTheme = (ImageView) findViewById(R.id.button_selectTheme); button_selectTheme.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { chooseTheme(); } }); }