List of usage examples for android.content Intent getParcelableExtra
public <T extends Parcelable> T getParcelableExtra(String name)
From source file:ca.mimic.apphangar.Settings.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { Tools.HangarLog("ResultCode: " + resultCode + "RequestCode: " + requestCode + "Intent: " + data); if (requestCode == 1001) { int responseCode = data.getIntExtra("RESPONSE_CODE", 0); String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA"); if (responseCode == 0) { try { JSONObject jo = new JSONObject(purchaseData); String sku = jo.getString("productId"); Tools.HangarLog("It werked! productId: " + sku); launchThanks(THANK_YOU_GOOGLE); } catch (JSONException e) { e.printStackTrace();//from w ww. j ava 2s.c om } } else { if (responseCode > 1) { Tools.HangarLog("Not user's fault, tried to purchase but bailed."); Toast.makeText(mContext, getResources().getString(R.string.donate_try_paypal), Toast.LENGTH_LONG).show(); } launchDonate(); } } else if (requestCode == 1) { // Icon chooser if (resultCode == Activity.RESULT_OK) { try { Bitmap bitmap = data.getParcelableExtra("icon"); ComponentName componentTask = ComponentName .unflattenFromString(mIconTask.getPackageName() + "/" + mIconTask.getClassName()); IconCacheHelper.preloadComponent(mContext, componentTask, bitmap, Tools.dpToPx(mContext, CACHED_ICON_SIZE)); myService.execute(SERVICE_CREATE_NOTIFICATIONS); completeRedraw = true; Tools.updateWidget(mContext); } catch (Exception e) { Tools.HangarLog("Icon result exception: " + e); } } } else if (requestCode == 2) { // Icon chooser if (resultCode == Activity.RESULT_OK) { try { Bitmap bitmap = data.getParcelableExtra("icon"); IconCacheHelper.preloadIcon(mContext, Settings.MORE_APPS_PACKAGE, bitmap, Tools.dpToPx(mContext, CACHED_ICON_SIZE)); myService.execute(SERVICE_CREATE_NOTIFICATIONS); completeRedraw = true; Tools.updateWidget(mContext); updateMoreAppsIcon(mContext); } catch (Exception e) { Tools.HangarLog("Icon result exception: " + e); } } } }
From source file:com.dycody.android.idealnote.ListFragment.java
@Override public// Used to show a Crouton dialog after saved (or tried to) a note void onActivityResult(int requestCode, final int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); switch (requestCode) { case REQUEST_CODE_CATEGORY: // Dialog retarded to give time to activity's views of being completely initialized // The dialog style is choosen depending on result code switch (resultCode) { case Activity.RESULT_OK: Toast.makeText(getActivity(), R.string.category_saved, Toast.LENGTH_SHORT).show(); //mainActivity.showMessage(R.string.category_saved, ONStyle.CONFIRM); EventBus.getDefault().post(new CategoriesUpdatedEvent()); break; case Activity.RESULT_FIRST_USER: Toast.makeText(getActivity(), R.string.category_deleted, Toast.LENGTH_SHORT).show(); //mainActivity.showMessage(R.string.category_deleted, ONStyle.ALERT); break; default:/* w w w . ja v a 2s . co m*/ break; } break; case REQUEST_CODE_CATEGORY_NOTES: if (intent != null) { Category tag = intent.getParcelableExtra(Constants.INTENT_CATEGORY); categorizeNotesExecute(tag); } break; case REQUEST_CODE_ADD_ALARMS: list.clearChoices(); selectedNotes.clear(); finishActionMode(); list.invalidateViews(); break; default: break; } }
From source file:com.httrack.android.HTTrackActivity.java
@Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { Log.d(getClass().getSimpleName(), "onActivityResult"); super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case ACTIVITY_OPTIONS: if (resultCode == Activity.RESULT_OK) { // Load modified map loadParcelable(data.getParcelableExtra("com.httrack.android.map")); }/*w ww. ja va2s . co m*/ break; case ACTIVITY_FILE_CHOOSER: if (resultCode == Activity.RESULT_OK) { // Load modified map final String path = data.getStringExtra("com.httrack.android.rootFile"); setBasePath(path); } break; case ACTIVITY_PROJECT_NAME_CHOOSER: if (resultCode == Activity.RESULT_OK) { final String projectName = data.getStringExtra("com.httrack.android.projectName"); final EditText name = EditText.class.cast(this.findViewById(R.id.fieldProjectName)); name.setText(projectName); name.setSelection(projectName.length()); name.requestFocus(); } break; case ACTIVITY_CLEANUP: if (resultCode == Activity.RESULT_OK) { final boolean rootWasDeleted = data.getBooleanExtra("com.httrack.android.rootPathWasDeleted", false); // Exit because otherwise we can't recreate the directory (!) if (rootWasDeleted && android.os.Build.VERSION.SDK_INT >= VERSION_CODES.KITKAT) { Log.w("httrack", "exiting because root path was deleted (Android >= Kitkat issue)"); // restartActivity(); finish(); // darn, this is not clean, but otherwise restarting the activity // won't be enough. I suspect FUSE-related issue here System.exit(0); } } break; } }
From source file:com.brandroidtools.filemanager.activities.NavigationActivity.java
/** * {@inheritDoc}// www .j a v a 2 s . com */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (data != null) { switch (requestCode) { case INTENT_REQUEST_BOOKMARK: if (resultCode == RESULT_OK) { FileSystemObject fso = (FileSystemObject) data.getSerializableExtra(EXTRA_BOOKMARK_SELECTION); if (fso != null) { //Open the fso getCurrentNavigationFragment().open(fso); } } break; case INTENT_REQUEST_HISTORY: if (resultCode == RESULT_OK) { //Change current directory History history = (History) data.getSerializableExtra(EXTRA_HISTORY_ENTRY_SELECTION); navigateToHistory(history); } else if (resultCode == RESULT_CANCELED) { boolean clear = data.getBooleanExtra(EXTRA_HISTORY_CLEAR, false); if (clear) { clearHistory(); } } break; case INTENT_REQUEST_SEARCH: if (resultCode == RESULT_OK) { //Change directory? FileSystemObject fso = (FileSystemObject) data .getSerializableExtra(EXTRA_SEARCH_ENTRY_SELECTION); SearchInfoParcelable searchInfo = data.getParcelableExtra(EXTRA_SEARCH_LAST_SEARCH_DATA); if (fso != null) { //Goto to new directory getCurrentNavigationFragment().open(fso, searchInfo); } } else if (resultCode == RESULT_CANCELED) { SearchInfoParcelable searchInfo = data.getParcelableExtra(EXTRA_SEARCH_LAST_SEARCH_DATA); if (searchInfo != null && searchInfo.isSuccessNavigation()) { //Navigate to previous history back(); } else { // I don't know is the search view was changed, so try to do a refresh // of the navigation view getCurrentNavigationFragment().refresh(true); } } break; default: break; } } }
From source file:com.piusvelte.taplock.client.core.TapLockService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (intent != null) { String action = intent.getAction(); if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) { int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_OFF); if (state == BluetoothAdapter.STATE_ON) { if (mStartedBT) { if (mUIInterface != null) { try { mUIInterface.setMessage("Bluetooth enabled"); } catch (RemoteException e) { Log.e(TAG, e.getMessage()); }/*from ww w .j a va2 s.c om*/ } if ((mQueueAddress != null) && (mQueueState != null)) requestWrite(mQueueAddress, mQueueState, mQueuePassphrase); else if (mRequestDiscovery && !mBtAdapter.isDiscovering()) mBtAdapter.startDiscovery(); else if (mUIInterface != null) { try { mUIInterface.setBluetoothEnabled(); } catch (RemoteException e) { Log.e(TAG, e.getMessage()); } } } } else if (state == BluetoothAdapter.STATE_TURNING_OFF) { if (mUIInterface != null) { try { mUIInterface.setMessage("Bluetooth disabled"); } catch (RemoteException e) { Log.e(TAG, e.getMessage()); } } stopThreads(); } } else if (BluetoothDevice.ACTION_FOUND.equals(action)) { // Get the BluetoothDevice object from the Intent BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); if (device.getBondState() == BluetoothDevice.BOND_BONDED) { // connect if configured String address = device.getAddress(); for (JSONObject deviceJObj : mDevices) { try { if (deviceJObj.getString(KEY_ADDRESS).equals(address)) { // if queued mDeviceFound = (mQueueAddress != null) && mQueueAddress.equals(address) && (mQueueState != null); break; } } catch (JSONException e) { Log.e(TAG, e.getMessage()); } } } else if (mRequestDiscovery && (mUIInterface != null)) { String unpairedDevice = TapLock .createDevice(device.getName(), device.getAddress(), DEFAULT_PASSPHRASE).toString(); try { mUIInterface.setUnpairedDevice(unpairedDevice); } catch (RemoteException e) { Log.e(TAG, e.getMessage()); } } } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) { if (mDeviceFound) { requestWrite(mQueueAddress, mQueueState, mQueuePassphrase); mDeviceFound = false; } else if (mRequestDiscovery) { mRequestDiscovery = false; if (mUIInterface != null) { try { mUIInterface.setDiscoveryFinished(); } catch (RemoteException e) { Log.e(TAG, e.toString()); } } } } else if (ACTION_TOGGLE.equals(action) && intent.hasExtra(EXTRA_DEVICE_ADDRESS)) { String address = intent.getStringExtra(EXTRA_DEVICE_ADDRESS); requestWrite(address, ACTION_TOGGLE, null); } else if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) { // create widget if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) { int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); if (intent.hasExtra(EXTRA_DEVICE_NAME)) { // add a widget String deviceName = intent.getStringExtra(EXTRA_DEVICE_NAME); for (int i = 0, l = mDevices.size(); i < l; i++) { String name = null; try { name = mDevices.get(i).getString(KEY_NAME); } catch (JSONException e1) { e1.printStackTrace(); } if ((name != null) && name.equals(deviceName)) { JSONObject deviceJObj = mDevices.remove(i); JSONArray widgetsJArr; if (deviceJObj.has(KEY_WIDGETS)) { try { widgetsJArr = deviceJObj.getJSONArray(KEY_WIDGETS); } catch (JSONException e) { widgetsJArr = new JSONArray(); } } else widgetsJArr = new JSONArray(); widgetsJArr.put(appWidgetId); try { deviceJObj.put(KEY_WIDGETS, widgetsJArr); } catch (JSONException e) { e.printStackTrace(); } mDevices.add(i, deviceJObj); TapLock.storeDevices(this, getSharedPreferences(KEY_PREFS, MODE_PRIVATE), mDevices); break; } } } buildWidget(appWidgetId); } else if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS)) { int[] appWidgetIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS); if (appWidgetIds != null) { for (int appWidgetId : appWidgetIds) buildWidget(appWidgetId); } } } else if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) { int appWidgetId = intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); Log.d(TAG, "delete appWidgetId: " + appWidgetId); for (int i = 0, l = mDevices.size(); i < l; i++) { JSONObject deviceJObj = mDevices.get(i); if (deviceJObj.has(KEY_WIDGETS)) { JSONArray widgetsJArr = null; try { widgetsJArr = deviceJObj.getJSONArray(KEY_WIDGETS); } catch (JSONException e) { e.printStackTrace(); } if (widgetsJArr != null) { boolean wasUpdated = false; JSONArray newWidgetsJArr = new JSONArray(); for (int widgetIdx = 0, wdigetsLen = widgetsJArr .length(); widgetIdx < wdigetsLen; widgetIdx++) { int widgetId; try { widgetId = widgetsJArr.getInt(widgetIdx); } catch (JSONException e) { widgetId = AppWidgetManager.INVALID_APPWIDGET_ID; e.printStackTrace(); } Log.d(TAG, "eval widgetId: " + widgetId); if ((widgetId != AppWidgetManager.INVALID_APPWIDGET_ID) && (widgetId == appWidgetId)) { Log.d(TAG, "skip: " + widgetId); wasUpdated = true; } else { Log.d(TAG, "include: " + widgetId); newWidgetsJArr.put(widgetId); } } if (wasUpdated) { try { deviceJObj.put(KEY_WIDGETS, newWidgetsJArr); mDevices.remove(i); mDevices.add(i, deviceJObj); TapLock.storeDevices(this, getSharedPreferences(KEY_PREFS, MODE_PRIVATE), mDevices); Log.d(TAG, "stored: " + deviceJObj.toString()); } catch (JSONException e) { e.printStackTrace(); } } } } else { JSONArray widgetsJArr = new JSONArray(); try { deviceJObj.put(KEY_WIDGETS, widgetsJArr); mDevices.remove(i); mDevices.add(i, deviceJObj); TapLock.storeDevices(this, getSharedPreferences(KEY_PREFS, MODE_PRIVATE), mDevices); } catch (JSONException e) { e.printStackTrace(); } } } } } return START_STICKY; }
From source file:com.android.contacts.ContactSaveService.java
private void updateGroup(Intent intent) { long groupId = intent.getLongExtra(EXTRA_GROUP_ID, -1); String label = intent.getStringExtra(EXTRA_GROUP_LABEL); long[] rawContactsToAdd = intent.getLongArrayExtra(EXTRA_RAW_CONTACTS_TO_ADD); long[] rawContactsToRemove = intent.getLongArrayExtra(EXTRA_RAW_CONTACTS_TO_REMOVE); if (groupId == -1) { Log.e(TAG, "Invalid arguments for updateGroup request"); return;/*from ww w . ja v a 2s . c o m*/ } final ContentResolver resolver = getContentResolver(); final Uri groupUri = ContentUris.withAppendedId(Groups.CONTENT_URI, groupId); // Update group name if necessary if (label != null) { ContentValues values = new ContentValues(); values.put(Groups.TITLE, label); resolver.update(groupUri, values, null, null); } // Add and remove members if necessary addMembersToGroup(resolver, rawContactsToAdd, groupId); removeMembersFromGroup(resolver, rawContactsToRemove, groupId); Intent callbackIntent = intent.getParcelableExtra(EXTRA_CALLBACK_INTENT); callbackIntent.setData(groupUri); deliverCallback(callbackIntent); }
From source file:com.ifoer.expeditionphone.MainActivity.java
public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_CONNECT_DEVICE /*1*/: if (serialPort != null) { Constant.mChatService.connect(serialPort, f2129D); }/*from w w w . j a va 2 s . c om*/ case REQUEST_CIRCLE_ADD_IMAGE /*3*/: if (data != null) { Bitmap photo = (Bitmap) data.getParcelableExtra(DataPacketExtension.ELEMENT_NAME); if (photo == null) { Toast.makeText(this, C0136R.string.toast_select_image, 0).show(); return; } ByteArrayOutputStream outStream = new ByteArrayOutputStream(); photo.compress(CompressFormat.JPEG, 20, outStream); imageStr = MyApplication.encode(outStream.toByteArray()); } case TrafficIncident.LOCATION_FIELD_NUMBER /*11*/: if (resultCode == 10) { this.showDialogFlag = data.getExtras().getInt(IfShowDialog, 0); checkIfFirstCome(); if (data.getExtras().getInt("findPassword", 0) == REQUEST_CONNECT_DEVICE && panel == null) { this.initSlidingFlag = 6; } } else if (resultCode != 11 || data.getExtras().getInt("findPassword", 0) != REQUEST_CONNECT_DEVICE) { } else { if (panel != null) { startActivity(new Intent(this, FindPwdActivity.class)); return; } this.initSlidingFlag = 6; } case REQUEST_USER_LOGIN_OUT /*25*/: if (resultCode == 11) { startActivity(new Intent(this, FindPwdActivity.class)); } else if (resultCode == 10) { initLeftBtn(contexts, REQUEST_CONNECT_DEVICE); panel.removePanelContainer(); panel.fillPanelContainer(new DiagnosisdatabaseActivity(contexts)); panel.openthreePanelContainer(); } case XStream.PRIORITY_VERY_HIGH /*10000*/: if (data != null) { if (!XmlPullParser.NO_NAMESPACE.equals(data.getStringExtra("CAMERA"))) { FastDiagnosisActivity.mVin = data.getStringExtra("CAMERA"); FastDiagnosisActivity.etVin.setText(data.getStringExtra("CAMERA")); } } case FastDiagnosisActivity.PHOTO_ALBUM_REQUEST_CODE /*10001*/: if (data == null) { return; } if (resultCode != -1) { Toast.makeText(this, C0136R.string.ImageGetFail, 0).show(); } else if (Environment.getExternalStorageState().equals("mounted")) { Uri uri = data.getData(); String[] proj = new String[REQUEST_CONNECT_DEVICE]; proj[0] = "_data"; Cursor cursor = managedQuery(uri, proj, null, null, null); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow("_data"); if (cursor.getCount() <= 0 || !cursor.moveToFirst()) { Toast.makeText(this, C0136R.string.circleImageNoFound, 0).show(); return; } String mImagePath = cursor.getString(column_index); Intent intentPhoto = new Intent(this, VinPhotoActivity.class); intentPhoto.putExtra("IMAGE_PATH", mImagePath); startActivityForResult(intentPhoto, XStream.PRIORITY_VERY_HIGH); return; } Toast.makeText(this, C0136R.string.circleImageNoFound, 0).show(); } else { Toast.makeText(this, C0136R.string.circleSDDisable, 0).show(); } case FastDiagnosisActivity.VOICE_RECOGNITION_REQUEST_CODE /*10002*/: if (data != null) { if (!XmlPullParser.NO_NAMESPACE.equals(data.getStringExtra("VOICE"))) { String mStrVin = FastDiagnosisActivity.str2NumbersOrLetters(data.getStringExtra("VOICE")) .replace(MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR, XmlPullParser.NO_NAMESPACE) .toUpperCase(); Intent intent = new Intent("SPT_SET_VIN"); intent.putExtra("SPT_SET_VIN", mStrVin); contexts.sendBroadcast(intent); } } default: } }
From source file:com.ubiLive.GameCloud.Browser.WebBrowser.java
private void processNetworkType(Intent intent, Context context) { int netType;/*from ww w. jav a 2s . c o m*/ int netSubtype; int networkType; boolean isConnected; String reloadUrl; DebugLog.d(TAG, "processNetworkType() enter"); NetworkInfo netInfo = Utils.getCurNetworkInfo(context); if (netInfo == null || netInfo.isAvailable() == false) { DebugLog.d(TAG, "getCurNetworkInfo() is null"); netInfo = (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO); } if (netInfo == null || netInfo.isAvailable() == false) { DebugLog.d(TAG, "getCurNetworkInfo() netInfo is null line1383"); if (mbNetworIsConnect != false) { mbNetworIsConnect = false; reloadUrl = GameInfo.getErrorUrl(); reload(reloadUrl); } Utils.setNetworkType(Constants.NETWORKTYPE_NONE); return; } netType = netInfo.getType(); netSubtype = netInfo.getSubtype(); isConnected = netInfo.isConnected(); DebugLog.e(TAG, "======processNetworkType nettype = " + netType + ",netSubtype = " + netSubtype + ",isConnect = " + isConnected); switch (netType) { case ConnectivityManager.TYPE_MOBILE_SUPL: case ConnectivityManager.TYPE_MOBILE_MMS: case ConnectivityManager.TYPE_MOBILE_HIPRI: case ConnectivityManager.TYPE_MOBILE_DUN: case ConnectivityManager.TYPE_MOBILE: DebugLog.d(TAG, "processNetworkType ConnectivityManager.TYPE_MOBILE netSubtype=" + netSubtype); if (netSubtype == TelephonyManager.NETWORK_TYPE_LTE) {//4 DebugLog.d(TAG, "processNetworkType ConnectivityManager.TYPE_MOBILE 4G"); networkType = Constants.NETWORKTYPE_LTE; } else {//3 DebugLog.d(TAG, "processNetworkType ConnectivityManager.TYPE_MOBILE 3G"); networkType = Constants.NETWORKTYPE_3G; } break; case ConnectivityManager.TYPE_WIFI: DebugLog.d(TAG, "processNetworkType ConnectivityManager.TYPE_WIFI"); networkType = Constants.NETWORKTYPE_WIFI; break; case ConnectivityManager.TYPE_ETHERNET: DebugLog.d(TAG, "processNetworkType ConnectivityManager.TYPE_ETHERNET"); networkType = Constants.NETWORKTYPE_ETHERNET; break; default: DebugLog.d(TAG, "other network status"); networkType = Constants.NETWORKTYPE_OTHERS; break; } DebugLog.e(TAG, "======processNetworkType nettype = " + netType + ",netSubtype = " + netSubtype + ",isConnect = " + isConnected + ",mbNetworIsConnect = " + mbNetworIsConnect); if (isConnected) { reloadUrl = Utils.checkUrl(GameInfo.DEFAULT_URL); Utils.setNetworkType(networkType); // Utils.setNetworkType(Constants.NETWORKTYPE_WIFI);//temp change } else { reloadUrl = GameInfo.getErrorUrl(); Utils.setNetworkType(Constants.NETWORKTYPE_NONE); } // if((networkType == Constants.NETWORKTYPE_WIFI || networkType == Constants.NETWORKTYPE_LTE) && mbNetworIsConnect != isConnected){ if (mbNetworIsConnect != isConnected) { mbNetworIsConnect = isConnected; reload(reloadUrl); DebugLog.d(TAG, "Notify reload finish"); } }
From source file:com.nttec.everychan.ui.ShareActivity.java
private void handleIntent(Intent intent) { ArrayAdapter<Pair<TabModel, SerializablePage>> adapter = new ArrayAdapter<Pair<TabModel, SerializablePage>>( this, 0) { private final int drawablePadding = (int) (getResources().getDisplayMetrics().density * 5 + 0.5f); @Override/* w ww. j av a 2s . c om*/ public View getView(int position, View convertView, ViewGroup parent) { View view = convertView == null ? getLayoutInflater().inflate(android.R.layout.simple_list_item_1, parent, false) : convertView; TextView tv = (TextView) view.findViewById(android.R.id.text1); tv.setEllipsize(TextUtils.TruncateAt.END); tv.setSingleLine(); tv.setText(getItem(position).getLeft().title); tv.setCompoundDrawablesWithIntrinsicBounds(MainApplication.getInstance() .getChanModule(getItem(position).getLeft().pageModel.chanName).getChanFavicon(), null, null, null); tv.setCompoundDrawablePadding(drawablePadding); return view; } }; for (TabModel tab : MainApplication.getInstance().tabsState.tabsArray) { if (tab.type == TabModel.TYPE_NORMAL && tab.pageModel.type != UrlPageModel.TYPE_SEARCHPAGE) { SerializablePage page = MainApplication.getInstance().pagesCache.getSerializablePage(tab.hash); if (page != null) { adapter.add(Pair.of(tab, page)); } } } if (adapter.getCount() == 0) { for (Database.HistoryEntry entity : MainApplication.getInstance().database.getHistory()) { try { TabModel tab = new TabModel(); tab.title = entity.title; tab.type = TabModel.TYPE_NORMAL; tab.webUrl = entity.url; tab.pageModel = UrlHandler.getPageModel(entity.url); tab.hash = ChanModels.hashUrlPageModel(tab.pageModel); SerializablePage page = MainApplication.getInstance().pagesCache.getSerializablePage(tab.hash); if (page != null) { adapter.add(Pair.of(tab, page)); } } catch (Exception e) { Logger.e(TAG, e); } } if (adapter.getCount() == 0) { Toast.makeText(this, R.string.share_no_tabs, Toast.LENGTH_LONG).show(); finish(); return; } } if (PostingService.isNowPosting()) { Toast.makeText(this, R.string.posting_now_posting, Toast.LENGTH_LONG).show(); finish(); return; } selectedFile = null; if (intent != null) { Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM); if (uri != null) { File file = UriFileUtils.getFile(this, uri); if (file != null) { selectedFile = file; } } } if (selectedFile == null) { Toast.makeText(this, R.string.postform_cannot_attach, Toast.LENGTH_LONG).show(); finish(); return; } setListAdapter(adapter); }
From source file:com.koma.music.service.MusicService.java
private void setUpMediaSession() { mSession = new MediaSession(this, "KomaMusic"); mSession.setCallback(new MediaSession.Callback() { @Override/*from w ww . ja v a 2 s . c o m*/ public void onPause() { pause(); mPausedByTransientLossOfFocus = false; } @Override public void onPlay() { play(); } @Override public void onSeekTo(long pos) { seek(pos); } @Override public void onSkipToNext() { gotoNext(true); } @Override public void onSkipToPrevious() { prev(false); } @Override public void onStop() { pause(); mPausedByTransientLossOfFocus = false; seek(0); releaseServiceUiAndStop(); } @Override public void onSkipToQueueItem(long id) { setQueuePosition((int) id); } @Override public boolean onMediaButtonEvent(@NonNull Intent mediaButtonIntent) { if (Intent.ACTION_MEDIA_BUTTON.equals(mediaButtonIntent.getAction())) { KeyEvent ke = mediaButtonIntent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (ke != null && ke.getKeyCode() == KeyEvent.KEYCODE_HEADSETHOOK) { if (ke.getAction() == KeyEvent.ACTION_UP) { handleHeadsetHookClick(ke.getEventTime()); } return true; } } return super.onMediaButtonEvent(mediaButtonIntent); } }); PendingIntent pi = PendingIntent.getBroadcast(this, 0, new Intent(this, MediaButtonIntentReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT); mSession.setMediaButtonReceiver(pi); mSession.setFlags(MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS | MediaSession.FLAG_HANDLES_MEDIA_BUTTONS); }