List of usage examples for android.content Intent getSerializableExtra
public Serializable getSerializableExtra(String name)
From source file:com.wordpress.bennthomsen.ble_uart_remote.MainActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_SELECT_DEVICE: //When the DeviceListActivity return, with the selected device address if (resultCode == Activity.RESULT_OK && data != null) { String deviceAddress = data.getStringExtra(BluetoothDevice.EXTRA_DEVICE); mDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(deviceAddress); Log.d(TAG, "... onActivityResultdevice.address==" + mDevice + "mserviceValue" + mService); ((TextView) findViewById(R.id.deviceName)).setText(mDevice.getName() + " - connecting"); mService.connect(deviceAddress); }/* w w w .ja v a 2 s .co m*/ break; case REQUEST_ENABLE_BT: // When the request to enable Bluetooth returns if (resultCode == Activity.RESULT_OK) { Toast.makeText(this, "Bluetooth has turned on ", Toast.LENGTH_SHORT).show(); } else { // User did not enable Bluetooth or an error occurred Log.d(TAG, "BT not enabled"); Toast.makeText(this, "Problem in BT Turning ON ", Toast.LENGTH_SHORT).show(); finish(); } break; case MainActivity.REQUEST_SELECT_RECIPE: if (resultCode != Activity.RESULT_CANCELED) { value = null; bakery = (Bakery) data.getSerializableExtra("bakery"); recipe = (Recipe) data.getSerializableExtra("recipe"); value = bakery.setProgram(value); new AlertDialog.Builder(this).setTitle("Ateno").setMessage( "Antes de continuar, cetifique-se que a bandeja foi inserida com todos os ingredientes.") .setPositiveButton("Continuar", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //send program to the machine mService.writeRXCharacteristic(value); } }).show(); //register this operation in cloud } break; default: Log.e(TAG, "wrong request code"); break; } }
From source file:com.massivcode.androidmusicplayer.services.MusicService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (intent != null && intent.getAction() != null) { mAction = intent.getAction();/*from w ww . j a v a 2 s . co m*/ } if (mAction == null) { EventBus.getDefault().post(new FinishActivity()); stopForeground(true); stopService(new Intent(getApplicationContext(), MusicService.class)); return START_NOT_STICKY; } switch (mAction) { case ACTION_PLAY_SELECTED: mCurrentPosition = intent != null ? intent.getIntExtra("position", 0) : 0; mCurrentMusicInfo = MusicInfoLoadUtil.getSelectedMusicInfo(getApplicationContext(), mCurrentPlaylist.get(mCurrentPosition)); break; case ACTION_PLAY: mCurrentPlaylist = (ArrayList<Long>) (intent != null ? intent.getSerializableExtra("list") : null); mCurrentPosition = intent.getIntExtra("position", 0); mCurrentMusicInfo = MusicInfoLoadUtil.getSelectedMusicInfo(getApplicationContext(), mCurrentPlaylist.get(mCurrentPosition)); break; case ACTION_PLAY_NEXT: case ACTION_PLAY_PREVIOUS: boolean isShuffle = DataBackupUtil.getInstance(getApplicationContext()).loadIsShuffle(); if (isShuffle) { mCurrentPosition = shuffle(mCurrentPlaylist.size()); } else { mCurrentPosition = intent != null ? intent.getIntExtra("position", 0) : 0; } mCurrentMusicInfo = MusicInfoLoadUtil.getSelectedMusicInfo(getApplicationContext(), mCurrentPlaylist.get(mCurrentPosition)); break; case ACTION_FINISH: if (mMediaPlayer.isPlaying()) { mHandler.removeMessages(0); mMediaPlayer.stop(); mMediaPlayer.release(); mMediaPlayer = null; } else { mHandler.removeMessages(0); mMediaPlayer.release(); mMediaPlayer = null; } EventBus.getDefault().post(new FinishActivity()); stopForeground(true); stopService(new Intent(getApplicationContext(), MusicService.class)); break; case ACTION_PAUSE_UNPLUGGED: if (mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); if (mCurrentMusicInfo != null && mCurrentPlaylist != null) { sendAllEvent(); showNotification(); } } break; } switch (mAction) { case ACTION_PLAY_SELECTED: if (mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); mMediaPlayer.reset(); try { mMediaPlayer.setDataSource(getApplicationContext(), switchIdToUri(mCurrentPlaylist.get(mCurrentPosition))); mMediaPlayer.prepare(); isReady = true; // TODO ? sendAllEvent(); mMediaPlayer.start(); } catch (IOException e) { e.printStackTrace(); } finally { showNotification(); } } else { mMediaPlayer.reset(); try { mMediaPlayer.setDataSource(getApplicationContext(), switchIdToUri(mCurrentPlaylist.get(mCurrentPosition))); mMediaPlayer.prepare(); isReady = true; // TODO ? sendAllEvent(); mMediaPlayer.start(); } catch (IOException e) { e.printStackTrace(); } finally { showNotification(); } } break; case ACTION_PLAY: if (mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); mMediaPlayer.reset(); try { mMediaPlayer.setDataSource(getApplicationContext(), switchIdToUri(mCurrentPlaylist.get(mCurrentPosition))); mMediaPlayer.prepare(); isReady = true; // TODO ? sendAllEvent(); mMediaPlayer.start(); } catch (IOException e) { e.printStackTrace(); } finally { showNotification(); } } else { mMediaPlayer.reset(); try { mMediaPlayer.setDataSource(getApplicationContext(), switchIdToUri(mCurrentPlaylist.get(mCurrentPosition))); mMediaPlayer.prepare(); isReady = true; // TODO ? sendAllEvent(); mMediaPlayer.start(); } catch (IOException e) { e.printStackTrace(); } finally { showNotification(); } } break; case ACTION_PAUSE: if (mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } else { mMediaPlayer.start(); } if (mCurrentMusicInfo != null && mCurrentPlaylist != null) { sendAllEvent(); showNotification(); } break; case ACTION_PLAY_NEXT: // Log.d(TAG, "ACTION_PLAY_NEXT"); if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); mMediaPlayer.reset(); try { mMediaPlayer.setDataSource(getApplicationContext(), switchIdToUri(mCurrentPlaylist.get(mCurrentPosition))); mMediaPlayer.prepare(); isReady = true; // TODO ? sendAllEvent(); mMediaPlayer.start(); } catch (IOException e) { e.printStackTrace(); } finally { showNotification(); } } else { mMediaPlayer.reset(); try { mMediaPlayer.setDataSource(getApplicationContext(), switchIdToUri(mCurrentPlaylist.get(mCurrentPosition))); mMediaPlayer.prepare(); isReady = true; // TODO ? sendAllEvent(); mMediaPlayer.start(); } catch (IOException e) { e.printStackTrace(); } finally { showNotification(); } } break; case ACTION_PLAY_PREVIOUS: if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); mMediaPlayer.reset(); try { mMediaPlayer.setDataSource(getApplicationContext(), switchIdToUri(mCurrentPlaylist.get(mCurrentPosition))); mMediaPlayer.prepare(); isReady = true; // TODO ? sendAllEvent(); mMediaPlayer.start(); } catch (IOException e) { e.printStackTrace(); } finally { showNotification(); } } else { mMediaPlayer.reset(); try { mMediaPlayer.setDataSource(getApplicationContext(), switchIdToUri(mCurrentPlaylist.get(mCurrentPosition))); mMediaPlayer.prepare(); isReady = true; // TODO ? sendAllEvent(); mMediaPlayer.start(); } catch (IOException e) { e.printStackTrace(); } finally { showNotification(); } } break; } return START_STICKY; }
From source file:com.example.zf_android.activity.MerchantEdit.java
@Override protected void onActivityResult(final int requestCode, int resultCode, final Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode != RESULT_OK) { return;/*w ww . j a v a2 s.co m*/ } String value = ""; if (data != null) { value = data.getStringExtra("value"); } switch (requestCode) { case TYPE_1: merchantEntity.setTitle(value); tv1.setText(value); break; case TYPE_2: merchantEntity.setLegalPersonName(value); tv2.setText(value); break; case TYPE_3: merchantEntity.setLegalPersonCardId(value); tv3.setText(value); break; case TYPE_4: merchantEntity.setBusinessLicenseNo(value); tv4.setText(value); break; case TYPE_5: merchantEntity.setTaxRegisteredNo(value); tv5.setText(value); break; case TYPE_6: merchantEntity.setOrganizationCodeNo(value); tv6.setText(value); break; case TYPE_7: Province province = (Province) data.getSerializableExtra(Constants.CityIntent.SELECTED_PROVINCE); City city = (City) data.getSerializableExtra(Constants.CityIntent.SELECTED_CITY); if (province == null || city == null) { merchantEntity.setCityId(0); tv7.setText(""); } else { merchantEntity.setCityId(city.getId()); tv7.setText(province.getName() + city.getName()); } break; case TYPE_KHYH: merchantEntity.setAccountBankName(value); tvkhyh.setText(value); break; case TYPE_8: merchantEntity.setBankOpenAccount(value); tv8.setText(value); break; case REQUEST_UPLOAD_IMAGE: case REQUEST_TAKE_PHOTO: { final LinearLayout layout = linearLayout.get(MerchantEdit.this.type); final Handler handler = new Handler() { private int type; @Override public void handleMessage(Message msg) { this.type = MerchantEdit.this.type; if (msg.what == 1) { // CommonUtil.toastShort(MerchantEdit.this, // (String) msg.obj); layout.setClickable(false); layout.findViewById(R.id.imgView).setVisibility(View.VISIBLE); layout.findViewById(R.id.textView).setVisibility(View.GONE); String url = (String) msg.obj; layout.setClickable(true); switch (type) { case TYPE_10: merchantEntity.setCardIdFrontPhotoPath(url); break; case TYPE_11: merchantEntity.setCardIdBackPhotoPath(url); break; case TYPE_12: merchantEntity.setBodyPhotoPath(url); break; case TYPE_13: merchantEntity.setLicenseNoPicPath(url); break; case TYPE_14: merchantEntity.setTaxNoPicPath(url); break; case TYPE_15: merchantEntity.setOrgCodeNoPicPath(url); break; case TYPE_16: merchantEntity.setAccountPicPath(url); break; default: break; } } else { CommonUtil.toastShort(MerchantEdit.this, getString(R.string.toast_upload_failed)); layout.setClickable(true); } } }; if (null != layout) { ImageView imgView = (ImageView) layout.findViewById(R.id.imgView); TextView textView = (TextView) layout.findViewById(R.id.textView); imgView.setVisibility(View.GONE); textView.setVisibility(View.VISIBLE); textView.setText(getString(R.string.apply_uploading)); layout.setClickable(false); } new Thread() { @Override public void run() { String realPath = ""; if (requestCode == REQUEST_TAKE_PHOTO) { realPath = photoPath; } else { Uri uri = data.getData(); if (uri != null) { realPath = Tools.getRealPathFromURI(MerchantEdit.this, uri); } } if (TextUtils.isEmpty(realPath)) { handler.sendEmptyMessage(0); return; } CommonUtil.uploadFile(realPath, "img", new CommonUtil.OnUploadListener() { @Override public void onSuccess(String result) { try { JSONObject jo = new JSONObject(result); String url = jo.getString("result"); Message msg = new Message(); msg.what = 1; msg.obj = url; handler.sendMessage(msg); } catch (JSONException e) { handler.sendEmptyMessage(0); } } @Override public void onFailed(String message) { handler.sendEmptyMessage(0); } }); } }.start(); break; } default: break; } }
From source file:org.sipdroid.sipua.ui.Receiver.java
@Override public void onReceive(Context context, Intent intent) { String intentAction = intent.getAction(); if (!Sipdroid.on(context)) return;//from w w w. jav a 2s. co m if (!Sipdroid.release) Log.i("SipUA:", intentAction); if (mContext == null) mContext = context; if (intentAction.equals(Intent.ACTION_BOOT_COMPLETED)) { on_vpn(false); engine(context).register(); } else if (intentAction.equals(ConnectivityManager.CONNECTIVITY_ACTION) || intentAction.equals(ACTION_EXTERNAL_APPLICATIONS_AVAILABLE) || intentAction.equals(ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE) || intentAction.equals(Intent.ACTION_PACKAGE_REPLACED)) { engine(context).register(); } else if (intentAction.equals(ACTION_VPN_CONNECTIVITY) && intent.hasExtra("connection_state")) { String state = intent.getSerializableExtra("connection_state").toString(); if (state != null && on_vpn() != state.equals("CONNECTED")) { on_vpn(state.equals("CONNECTED")); for (SipProvider sip_provider : engine(context).sip_providers) if (sip_provider != null) sip_provider.haltConnections(); engine(context).register(); } } else if (intentAction.equals(ACTION_DATA_STATE_CHANGED)) { engine(context).registerMore(); } else if (intentAction.equals(ACTION_PHONE_STATE_CHANGED) && !intent.getBooleanExtra(context.getString(R.string.app_name), false)) { stopRingtone(); pstn_state = intent.getStringExtra("state"); pstn_time = SystemClock.elapsedRealtime(); if (pstn_state.equals("IDLE") && call_state != UserAgent.UA_STATE_IDLE) broadcastCallStateChanged(null, null); if (!pstn_state.equals("IDLE") && call_state == UserAgent.UA_STATE_INCALL) mHandler.sendEmptyMessageDelayed(MSG_HOLD, 5000); else if (!pstn_state.equals("IDLE") && (call_state == UserAgent.UA_STATE_INCOMING_CALL || call_state == UserAgent.UA_STATE_OUTGOING_CALL)) mHandler.sendEmptyMessageDelayed(MSG_HANGUP, 5000); else if (pstn_state.equals("IDLE")) { mHandler.removeMessages(MSG_HOLD); mHandler.removeMessages(MSG_HANGUP); if (call_state == UserAgent.UA_STATE_HOLD) mHandler.sendEmptyMessageDelayed(MSG_HOLD, 1000); } } else if (intentAction.equals(ACTION_DOCK_EVENT)) { docked = intent.getIntExtra(EXTRA_DOCK_STATE, -1) & 7; if (call_state == UserAgent.UA_STATE_INCALL) engine(mContext).speaker(speakermode()); } else if (intentAction.equals(ACTION_SCO_AUDIO_STATE_CHANGED)) { bluetooth = intent.getIntExtra(EXTRA_SCO_AUDIO_STATE, -1); progress(); RtpStreamSender.changed = true; } else if (intentAction.equals(Intent.ACTION_HEADSET_PLUG)) { headset = intent.getIntExtra("state", -1); if (call_state == UserAgent.UA_STATE_INCALL) engine(mContext).speaker(speakermode()); } else if (intentAction.equals(Intent.ACTION_SCREEN_ON)) { if (!PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean( org.sipdroid.sipua.ui.Settings.PREF_OWNWIFI, org.sipdroid.sipua.ui.Settings.DEFAULT_OWNWIFI)) alarm(0, OwnWifi.class); } else if (intentAction.equals(Intent.ACTION_USER_PRESENT)) { mHandler.sendEmptyMessageDelayed(MSG_ENABLE, 3000); } else if (intentAction.equals(Intent.ACTION_SCREEN_OFF)) { if (PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean( org.sipdroid.sipua.ui.Settings.PREF_OWNWIFI, org.sipdroid.sipua.ui.Settings.DEFAULT_OWNWIFI)) { WifiManager wm = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); WifiInfo wi = wm.getConnectionInfo(); if (wm.getWifiState() != WifiManager.WIFI_STATE_ENABLED || wi == null || wi.getSupplicantState() != SupplicantState.COMPLETED || wi.getIpAddress() == 0) alarm(2 * 60, OwnWifi.class); else alarm(15 * 60, OwnWifi.class); } if (SipdroidEngine.pwl != null) for (PowerManager.WakeLock pwl : SipdroidEngine.pwl) if (pwl != null && pwl.isHeld()) { pwl.release(); pwl.acquire(); } } else if (intentAction.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) { if (PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean( org.sipdroid.sipua.ui.Settings.PREF_SELECTWIFI, org.sipdroid.sipua.ui.Settings.DEFAULT_SELECTWIFI)) mHandler.sendEmptyMessageDelayed(MSG_SCAN, 3000); } else if (intentAction.equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) { if (SystemClock.uptimeMillis() > lastscan + 45000 && PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean( org.sipdroid.sipua.ui.Settings.PREF_SELECTWIFI, org.sipdroid.sipua.ui.Settings.DEFAULT_SELECTWIFI)) { WifiManager wm = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); WifiInfo wi = wm.getConnectionInfo(); String activeSSID = null; if (wi != null) activeSSID = wi.getSSID(); if (activeSSID != null && (activeSSID.length() == 0 || activeSSID.equals("0x"))) activeSSID = null; List<ScanResult> mScanResults = wm.getScanResults(); List<WifiConfiguration> configurations = wm.getConfiguredNetworks(); if (configurations != null) { WifiConfiguration bestconfig = null, maxconfig = null, activeconfig = null; for (final WifiConfiguration config : configurations) { if (maxconfig == null || config.priority > maxconfig.priority) { maxconfig = config; } if (config.SSID != null && (config.SSID.equals("\"" + activeSSID + "\"") || config.SSID.equals(activeSSID))) activeconfig = config; } ScanResult bestscan = null, activescan = null; if (mScanResults != null) for (final ScanResult scan : mScanResults) { for (final WifiConfiguration config : configurations) { if (config.SSID != null && config.SSID.equals("\"" + scan.SSID + "\"")) { if (bestscan == null || scan.level > bestscan.level) { bestscan = scan; bestconfig = config; } if (config == activeconfig) activescan = scan; } } } if (activescan != null) System.out.println("debug wifi asu(active)" + asu(activescan)); if (bestconfig != null && (activeconfig == null || bestconfig.priority != activeconfig.priority) && asu(bestscan) > asu(activescan) * 1.5 && /* (activeSSID == null || activescan != null) && */ asu(bestscan) > 22) { if (!Sipdroid.release) Log.i("SipUA:", "changing to " + bestconfig.SSID); if (activeSSID == null || !activeSSID.equals(bestscan.SSID)) wm.disconnect(); bestconfig.priority = maxconfig.priority + 1; wm.updateNetwork(bestconfig); wm.enableNetwork(bestconfig.networkId, true); wm.saveConfiguration(); if (activeSSID == null || !activeSSID.equals(bestscan.SSID)) wm.reconnect(); lastscan = SystemClock.uptimeMillis(); } else if (activescan != null && asu(activescan) < 15) { wm.disconnect(); wm.disableNetwork(activeconfig.networkId); wm.saveConfiguration(); } } } } }
From source file:it.geosolutions.android.map.MapsActivity.java
/** * Opena the Data List activity/*from ww w.jav a2 s.co m*/ * @param item * @return */ /* (non-Javadoc) * @see android.app.Activity#onActivityResult(int, int, android.content.Intent) */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == GetFeatureInfoLayerListActivity.BBOX_REQUEST && resultCode == RESULT_OK) { //the response can contain a feature to use to replace the current marker //on the map manageMarkerSubstitutionAction(data); } //controls can be refreshed getting the result of an intent, in this case // each control knows wich intent he sent with their requestCode/resultCode for (MapControl control : mapView.getControls()) { control.refreshControl(requestCode, resultCode, data); } //manager mapstore configuration load //TODO: with the new interface this will load a map instead of the mapstoreconfig if (data == null) return; Bundle b = data.getExtras(); if (requestCode == DATAPROPERTIES_REQUEST_CODE) { mapView.getOverlayController().redrawOverlays(); } else if (requestCode == MAPSTORE_REQUEST_CODE) { Resource resource = (Resource) data .getSerializableExtra(GeoStoreResourceDetailActivity.PARAMS.RESOURCE); if (resource != null) { String geoStoreUrl = data.getStringExtra(GeoStoreResourcesActivity.PARAMS.GEOSTORE_URL); MapStoreUtils.loadMapStoreConfig(geoStoreUrl, resource, this); } if (b.containsKey(MAPSTORE_CONFIG)) { overlayManager.loadMapStoreConfig((MapStoreConfiguration) b.getSerializable(MAPSTORE_CONFIG)); } } }
From source file:com.github.vgoliveira.panificadora.MainActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_SELECT_DEVICE: //When the DeviceListActivity return, with the selected device address if (resultCode == Activity.RESULT_OK && data != null) { String deviceAddress = data.getStringExtra(BluetoothDevice.EXTRA_DEVICE); mDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(deviceAddress); Log.d(TAG, "... onActivityResultdevice.address==" + mDevice + "mserviceValue" + mService); ((TextView) findViewById(R.id.deviceName)).setText(mDevice.getName() + " - connecting"); mService.connect(deviceAddress); }/* ww w. ja v a2 s. c o m*/ break; case REQUEST_ENABLE_BT: // When the request to enable Bluetooth returns if (resultCode == Activity.RESULT_OK) { Toast.makeText(this, "Bluetooth has turned on ", Toast.LENGTH_SHORT).show(); } else { // User did not enable Bluetooth or an error occurred Log.d(TAG, "BT not enabled"); Toast.makeText(this, "Problem in BT Turning ON ", Toast.LENGTH_SHORT).show(); finish(); } break; case MainActivity.REQUEST_SELECT_RECIPE: if (resultCode != Activity.RESULT_CANCELED) { value = null; bakery = (Bakery) data.getSerializableExtra("bakery"); recipe = (Recipe) data.getSerializableExtra("recipe"); value = bakery.setProgram(value); new AlertDialog.Builder(this).setTitle("Ateno").setMessage( "Antes de continuar, cetifique-se que a bandeja foi inserida com todos os ingredientes.") .setPositiveButton("Continuar", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //send program to the machine mService.writeRXCharacteristic(value); } }).show(); //register this operation in cloud } break; case MainActivity.REQUEST_FACEBOOK_LOGIN: Toast.makeText(MainActivity.this, "Return Facebook Login", Toast.LENGTH_SHORT).show(); String name = data.getStringExtra("name"); String fbId = data.getStringExtra("id"); String email = data.getStringExtra("email"); String gender = data.getStringExtra("gender"); String ageRange = data.getStringExtra("age_range"); Toast.makeText(MainActivity.this, "User name: " + name, Toast.LENGTH_SHORT).show(); Toast.makeText(MainActivity.this, "Facebook id: " + fbId, Toast.LENGTH_SHORT).show(); Toast.makeText(MainActivity.this, "User email: " + email, Toast.LENGTH_SHORT).show(); Toast.makeText(MainActivity.this, "Gender: " + gender, Toast.LENGTH_SHORT).show(); Toast.makeText(MainActivity.this, "Age range: " + ageRange, Toast.LENGTH_SHORT).show(); break; default: Log.e(TAG, "wrong request code"); break; } }
From source file:com.android.contacts.ContactSaveService.java
private void splitContact(Intent intent) { final long rawContactIds[][] = (long[][]) intent.getSerializableExtra(EXTRA_RAW_CONTACT_IDS); final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_RESULT_RECEIVER); final boolean hardSplit = intent.getBooleanExtra(EXTRA_HARD_SPLIT, false); if (rawContactIds == null) { Log.e(TAG, "Invalid argument for splitContact request"); if (receiver != null) { receiver.send(BAD_ARGUMENTS, new Bundle()); }/*from w ww . j a v a2 s . co m*/ return; } final int batchSize = MAX_CONTACTS_PROVIDER_BATCH_SIZE; final ContentResolver resolver = getContentResolver(); final ArrayList<ContentProviderOperation> operations = new ArrayList<>(batchSize); for (int i = 0; i < rawContactIds.length; i++) { for (int j = 0; j < rawContactIds.length; j++) { if (i != j) { if (!buildSplitTwoContacts(operations, rawContactIds[i], rawContactIds[j], hardSplit)) { if (receiver != null) { receiver.send(CP2_ERROR, new Bundle()); return; } } } } } if (operations.size() > 0 && !applyOperations(resolver, operations)) { if (receiver != null) { receiver.send(CP2_ERROR, new Bundle()); } return; } LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(BROADCAST_UNLINK_COMPLETE)); if (receiver != null) { receiver.send(CONTACTS_SPLIT, new Bundle()); } else { showToast(R.string.contactUnlinkedToast); } }
From source file:com.onegravity.contactpicker.core.ContactPickerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // check if all custom attributes are defined if (!checkTheming()) { finish();/*from w w w . j a va2 s . co m*/ return; } /* * Check if we have the READ_CONTACTS permission, if not --> terminate. */ try { int pid = android.os.Process.myPid(); PackageManager pckMgr = getPackageManager(); int uid = pckMgr.getApplicationInfo(getComponentName().getPackageName(), PackageManager.GET_META_DATA).uid; enforcePermission(Manifest.permission.READ_CONTACTS, pid, uid, "Contact permission hasn't been granted to this app, terminating."); } catch (PackageManager.NameNotFoundException | SecurityException e) { Log.e(getClass().getSimpleName(), e.getMessage()); finish(); return; } mDefaultTitle = "Select Contacts"; mThemeResId = R.style.Theme_Light; Intent intent = getIntent(); if (savedInstanceState == null) { // /* // * Retrieve default title used if no contacts are selected. // */ // try { // PackageManager pkMgr = getPackageManager(); // ActivityInfo activityInfo = pkMgr.getActivityInfo(getComponentName(), PackageManager.GET_META_DATA); // mDefaultTitle = activityInfo.loadLabel(pkMgr).toString(); // } // catch (PackageManager.NameNotFoundException ignore) { // mDefaultTitle = getTitle().toString(); // } if (intent.hasExtra(EXTRA_PRESELECTED_CONTACTS)) { Collection<Long> preselectedContacts = (Collection<Long>) intent .getSerializableExtra(EXTRA_PRESELECTED_CONTACTS); mSelectedContactIds.addAll(preselectedContacts); } if (intent.hasExtra(EXTRA_PRESELECTED_GROUPS)) { Collection<Long> preselectedGroups = (Collection<Long>) intent .getSerializableExtra(EXTRA_PRESELECTED_GROUPS); mSelectedGroupIds.addAll(preselectedGroups); } // mThemeResId = intent.getIntExtra(EXTRA_THEME, R.style.ContactPicker_Theme_Light); } else { // mDefaultTitle = savedInstanceState.getString("mDefaultTitle"); // // mThemeResId = savedInstanceState.getInt("mThemeResId"); // Retrieve selected contact and group ids. try { mSelectedContactIds = (HashSet<Long>) savedInstanceState.getSerializable(CONTACT_IDS); mSelectedGroupIds = (HashSet<Long>) savedInstanceState.getSerializable(GROUP_IDS); } catch (ClassCastException ignore) { } } /* * Retrieve ContactPictureType. */ String enumName = intent.getStringExtra(EXTRA_CONTACT_BADGE_TYPE); mBadgeType = ContactPictureType.lookup(enumName); /* * Retrieve SelectContactsLimit. */ mSelectContactsLimit = intent.getIntExtra(EXTRA_SELECT_CONTACTS_LIMIT, 0); /* * Retrieve ShowCheckAll. */ mShowCheckAll = mSelectContactsLimit > 0 ? false : intent.getBooleanExtra(EXTRA_SHOW_CHECK_ALL, true); /* * Retrieve OnlyWithPhoneNumbers. */ mOnlyWithPhoneNumbers = intent.getBooleanExtra(EXTRA_ONLY_CONTACTS_WITH_PHONE, false); /* * Retrieve LimitReachedMessage. */ String limitMsg = intent.getStringExtra(EXTRA_LIMIT_REACHED_MESSAGE); if (limitMsg != null) { mLimitReachedMessage = limitMsg; } else { mLimitReachedMessage = getString(R.string.cp_limit_reached, mSelectContactsLimit); } /* * Retrieve ContactDescription. */ enumName = intent.getStringExtra(EXTRA_CONTACT_DESCRIPTION); mDescription = ContactDescription.lookup(enumName); mDescriptionType = intent.getIntExtra(EXTRA_CONTACT_DESCRIPTION_TYPE, ContactsContract.CommonDataKinds.StructuredPostal.TYPE_HOME); /* * Retrieve ContactSortOrder. */ enumName = intent.getStringExtra(EXTRA_CONTACT_SORT_ORDER); mSortOrder = ContactSortOrder.lookup(enumName); setTheme(mThemeResId); setContentView(R.layout.cp_contact_tab_layout); // initialize TabLayout TabLayout tabLayout = (TabLayout) findViewById(R.id.tabContent); tabLayout.setTabMode(TabLayout.MODE_FIXED); tabLayout.setTabGravity(TabLayout.GRAVITY_FILL); TabLayout.Tab tabContacts = tabLayout.newTab(); tabContacts.setText(R.string.cp_contact_tab_title); tabLayout.addTab(tabContacts); TabLayout.Tab tabGroups = tabLayout.newTab(); tabGroups.setText(R.string.cp_group_tab_title); tabLayout.addTab(tabGroups); // initialize ViewPager final ViewPager viewPager = (ViewPager) findViewById(R.id.tabPager); mAdapter = new PagerAdapter(getSupportFragmentManager(), tabLayout.getTabCount(), mSortOrder, mBadgeType, mDescription, mDescriptionType); viewPager.setAdapter(mAdapter); viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { viewPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(TabLayout.Tab tab) { } @Override public void onTabReselected(TabLayout.Tab tab) { } }); getSupportActionBar().setDisplayHomeAsUpEnabled(true); }
From source file:com.example.zf_android.trade.ApplyDetailActivity.java
@Override protected void onActivityResult(final int requestCode, int resultCode, final Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode != RESULT_OK) return;/*ww w . j a v a2s . c o m*/ switch (requestCode) { case REQUEST_CHOOSE_MERCHANT: { mAgentId = mMerchantId = data.getIntExtra(AGENT_ID, 0); mAgentName = data.getStringExtra(AGENT_NAME); setItemValue(mMerchantKeys[0], mAgentName); getAgentInfo(); break; } case REQUEST_CHOOSE_BANK: { mBankName = data.getStringExtra("bank_name"); mBankNo = data.getStringExtra("bank_no"); setItemValue(customTag, mBankName); setItemValue(mBankKeys[0], mBankName); //FIXME no // setItemValue(mBankKeys[1], mBankNo); break; } case REQUEST_CHOOSE_CITY: { mMerchantProvince = (Province) data.getSerializableExtra(SELECTED_PROVINCE); mMerchantCity = (City) data.getSerializableExtra(SELECTED_CITY); mCityId = mMerchantCity.getId(); setItemValue(mMerchantKeys[8], mMerchantCity.getName()); break; } case REQUEST_CHOOSE_CHANNEL: { mChannelId = data.getIntExtra("channelId", 0); mBillingId = data.getIntExtra("billId", 0); String channelName = data.getStringExtra("channelName"); String billName = data.getStringExtra("billName"); setItemValue(getString(R.string.apply_detail_channel), channelName + " " + billName); break; } case REQUEST_UPLOAD_IMAGE: case REQUEST_TAKE_PHOTO: { final Handler handler = new Handler() { @Override public void handleMessage(Message msg) { if (msg.what == 1) { // CommonUtil.toastShort(ApplyDetailActivity.this, (String) msg.obj); if (null != uploadingTextView) { final String url = (String) msg.obj; LinearLayout item = (LinearLayout) uploadingTextView.getParent().getParent(); updateCustomerDetails(item.getTag(), url); uploadingTextView.setVisibility(View.GONE); ImageView iv_view = (ImageView) item.findViewById(R.id.apply_detail_view); iv_view.setVisibility(View.VISIBLE); iv_view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(ApplyDetailActivity.this, ImageViewer.class); i.putExtra("url", url); i.putExtra("justviewer", true); startActivity(i); } }); } } else { CommonUtil.toastShort(ApplyDetailActivity.this, getString(R.string.toast_upload_failed)); if (null != uploadingTextView) { uploadingTextView.setText(getString(R.string.apply_upload_again)); uploadingTextView.setClickable(true); } } } }; if (null != uploadingTextView) { uploadingTextView.setText(getString(R.string.apply_uploading)); uploadingTextView.setClickable(false); } new Thread() { @Override public void run() { String realPath = ""; if (requestCode == REQUEST_TAKE_PHOTO) { realPath = photoPath; } else { Uri uri = data.getData(); if (uri != null) { realPath = getRealPathFromURI(uri); } } if (TextUtils.isEmpty(realPath)) { handler.sendEmptyMessage(0); return; } CommonUtil.uploadFile(realPath, "img", new CommonUtil.OnUploadListener() { @Override public void onSuccess(String result) { try { JSONObject jo = new JSONObject(result); String url = jo.getString("result"); Message msg = new Message(); msg.what = 1; msg.obj = url; handler.sendMessage(msg); } catch (JSONException e) { handler.sendEmptyMessage(0); } } @Override public void onFailed(String message) { handler.sendEmptyMessage(0); } }); } }.start(); break; } } }
From source file:au.org.intersect.faims.android.ui.activity.ShowModuleActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { try {//from ww w. j a v a 2 s. co m if (resultCode == RESULT_CANCELED) { FLog.d("result cancelled"); return; } switch (requestCode) { case FILE_BROWSER_REQUEST_CODE: case RASTER_FILE_BROWSER_REQUEST_CODE: case SPATIAL_FILE_BROWSER_REQUEST_CODE: if (data != null) { @SuppressWarnings("unchecked") List<LocalFile> files = (List<LocalFile>) data .getSerializableExtra(FileChooserActivity._Results); if (files != null && files.size() > 0) { fm.selectFile(requestCode, files.get(0)); } } break; case CAMERA_REQUEST_CODE: if (resultCode == RESULT_OK) { this.linker.executeCameraCallBack(); } break; case VIDEO_REQUEST_CODE: if (resultCode == RESULT_OK) { this.linker.executeVideoCallBack(); } } } catch (Exception e) { FLog.e("error on activity result", e); } }