List of usage examples for android.os AsyncTask THREAD_POOL_EXECUTOR
Executor THREAD_POOL_EXECUTOR
To view the source code for android.os AsyncTask THREAD_POOL_EXECUTOR.
Click Source Link
From source file:im.vector.fragments.VectorSettingsPreferencesFragment.java
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Context appContext = getActivity().getApplicationContext(); // retrieve the arguments Bundle args = getArguments();//from w ww . j a va 2s.co m String matrixId = args.getString(ARG_MATRIX_ID); mSession = Matrix.getInstance(appContext).getSession(matrixId); // sanity checks if ((null == mSession) || !mSession.isAlive()) { getActivity().finish(); return; } // define the layout addPreferencesFromResource(R.xml.vector_settings_preferences); if (null == mPushesRuleByResourceId) { mPushesRuleByResourceId = new HashMap<>(); mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY, BingRule.RULE_ID_DISABLE_ALL); mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY, DUMMY_RULE); mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_TURN_SCREEN_ON_PREFERENCE_KEY, DUMMY_RULE); mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_CONTAINING_MY_DISPLAY_NAME_PREFERENCE_KEY, BingRule.RULE_ID_CONTAIN_DISPLAY_NAME); mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_CONTAINING_MY_USER_NAME_PREFERENCE_KEY, BingRule.RULE_ID_CONTAIN_USER_NAME); mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_MESSAGES_IN_ONE_TO_ONE_PREFERENCE_KEY, BingRule.RULE_ID_ONE_TO_ONE_ROOM); mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_MESSAGES_IN_GROUP_CHAT_PREFERENCE_KEY, BingRule.RULE_ID_ALL_OTHER_MESSAGES_ROOMS); mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_INVITED_TO_ROOM_PREFERENCE_KEY, BingRule.RULE_ID_INVITE_ME); mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_CALL_INVITATIONS_PREFERENCE_KEY, BingRule.RULE_ID_CALL); mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_MESSAGES_SENT_BY_BOT_PREFERENCE_KEY, BingRule.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS); } UserAvatarPreference avatarPreference = (UserAvatarPreference) findPreference( PreferencesManager.SETTINGS_PROFILE_PICTURE_PREFERENCE_KEY); avatarPreference.setSession(mSession); avatarPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { onUpdateAvatarClick(); return false; } }); EditTextPreference passwordPreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_CHANGE_PASSWORD_PREFERENCE_KEY); passwordPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { onPasswordUpdateClick(); return false; } }); EditTextPreference notificationRingTonePreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY); notificationRingTonePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION); if (null != PreferencesManager.getNotificationRingTone(getActivity())) { intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, PreferencesManager.getNotificationRingTone(getActivity())); } getActivity().startActivityForResult(intent, REQUEST_NOTIFICATION_RINGTONE); return false; } }); refreshNotificationRingTone(); EditTextPreference notificationPrivacyPreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_NOTIFICATION_PRIVACY_PREFERENCE_KEY); if (notificationPrivacyPreference != null) { notificationPrivacyPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { startActivity(NotificationPrivacyActivity.getIntent(getActivity())); return true; } }); refreshNotificationPrivacy(); } // application version VectorCustomActionEditTextPreference versionTextPreference = (VectorCustomActionEditTextPreference) findPreference( PreferencesManager.SETTINGS_VERSION_PREFERENCE_KEY); if (null != versionTextPreference) { versionTextPreference.setSummary(VectorUtils.getApplicationVersion(appContext)); versionTextPreference.setOnPreferenceLongClickListener( new VectorCustomActionEditTextPreference.OnPreferenceLongClickListener() { @Override public boolean onPreferenceLongClick(Preference preference) { VectorUtils.copyToClipboard(appContext, VectorUtils.getApplicationVersion(appContext)); return true; } }); } // olm version EditTextPreference olmTextPreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_OLM_VERSION_PREFERENCE_KEY); if (null != olmTextPreference) { olmTextPreference.setSummary( Matrix.getInstance(appContext).getDefaultSession().getCryptoVersion(appContext, false)); } // user account EditTextPreference accountIdTextPreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_LOGGED_IN_PREFERENCE_KEY); if (null != accountIdTextPreference) { accountIdTextPreference.setSummary(mSession.getMyUserId()); } // home server EditTextPreference homeServerTextPreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_HOME_SERVER_PREFERENCE_KEY); if (null != homeServerTextPreference) { homeServerTextPreference.setSummary(mSession.getHomeServerConfig().getHomeserverUri().toString()); } // identity server EditTextPreference identityServerTextPreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_IDENTITY_SERVER_PREFERENCE_KEY); if (null != identityServerTextPreference) { identityServerTextPreference .setSummary(mSession.getHomeServerConfig().getIdentityServerUri().toString()); } // terms & conditions EditTextPreference termConditionsPreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_APP_TERM_CONDITIONS_PREFERENCE_KEY); if (null != termConditionsPreference) { termConditionsPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { VectorUtils.displayAppTac(); return false; } }); } // Themes ListPreference themePreference = (ListPreference) findPreference(ThemeUtils.APPLICATION_THEME_KEY); if (null != themePreference) { themePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (newValue instanceof String) { VectorApp.updateApplicationTheme((String) newValue); getActivity().startActivity(getActivity().getIntent()); getActivity().finish(); return true; } else { return false; } } }); } // privacy policy EditTextPreference privacyPreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_PRIVACY_POLICY_PREFERENCE_KEY); if (null != privacyPreference) { privacyPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { VectorUtils.displayAppPrivacyPolicy(); return false; } }); } // third party notice EditTextPreference thirdPartyNotices = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_THIRD_PARTY_NOTICES_PREFERENCE_KEY); if (null != thirdPartyNotices) { thirdPartyNotices.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { VectorUtils.displayThirdPartyLicenses(); return false; } }); } // copyright EditTextPreference copyrightNotices = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_COPYRIGHT_PREFERENCE_KEY); if (null != copyrightNotices) { copyrightNotices.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { VectorUtils.displayAppCopyright(); return false; } }); } // update keep medias period final EditTextPreference keepMediaPeriodPreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_MEDIA_SAVING_PERIOD_KEY); if (null != keepMediaPeriodPreference) { keepMediaPeriodPreference .setSummary(PreferencesManager.getSelectedMediasSavingPeriodString(getActivity())); keepMediaPeriodPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { new AlertDialog.Builder(getActivity()) .setSingleChoiceItems(PreferencesManager.getMediasSavingItemsChoicesList(getActivity()), PreferencesManager.getSelectedMediasSavingPeriod(getActivity()), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface d, int n) { PreferencesManager.setSelectedMediasSavingPeriod(getActivity(), n); d.cancel(); keepMediaPeriodPreference.setSummary(PreferencesManager .getSelectedMediasSavingPeriodString(getActivity())); } }) .show(); return false; } }); } // clear medias cache final EditTextPreference clearMediaCachePreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_CLEAR_MEDIA_CACHE_PREFERENCE_KEY); if (null != clearMediaCachePreference) { MXMediasCache.getCachesSize(getActivity(), new SimpleApiCallback<Long>() { @Override public void onSuccess(Long size) { if (null != getActivity()) { clearMediaCachePreference .setSummary(android.text.format.Formatter.formatFileSize(getActivity(), size)); } } }); clearMediaCachePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { displayLoadingView(); AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { mSession.getMediasCache().clear(); Glide.get(getActivity()).clearDiskCache(); return null; } @Override protected void onPostExecute(Void result) { hideLoadingView(); MXMediasCache.getCachesSize(getActivity(), new SimpleApiCallback<Long>() { @Override public void onSuccess(Long size) { clearMediaCachePreference.setSummary( android.text.format.Formatter.formatFileSize(getActivity(), size)); } }); } }; try { task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } catch (Exception e) { Log.e(LOG_TAG, "## mSession.getMediasCache().clear() failed " + e.getMessage()); task.cancel(true); hideLoadingView(); } return false; } }); } // clear cache final EditTextPreference clearCachePreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_CLEAR_CACHE_PREFERENCE_KEY); if (null != clearCachePreference) { MXSession.getApplicationSizeCaches(getActivity(), new SimpleApiCallback<Long>() { @Override public void onSuccess(Long size) { if (null != getActivity()) { clearCachePreference .setSummary(android.text.format.Formatter.formatFileSize(getActivity(), size)); } } }); clearCachePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { displayLoadingView(); Matrix.getInstance(appContext).reloadSessions(appContext); return false; } }); } final EditTextPreference displaynamePref = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_DISPLAY_NAME_PREFERENCE_KEY); displaynamePref.setSummary(mSession.getMyUser().displayname); displaynamePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { onDisplayNameClick((null == newValue) ? null : ((String) newValue).trim()); return false; } }); final VectorSwitchPreference urlPreviewPreference = (VectorSwitchPreference) findPreference( PreferencesManager.SETTINGS_SHOW_URL_PREVIEW_KEY); urlPreviewPreference.setChecked(mSession.isURLPreviewEnabled()); urlPreviewPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if ((null != newValue) && ((boolean) newValue != mSession.isURLPreviewEnabled())) { displayLoadingView(); mSession.setURLPreviewStatus((boolean) newValue, new ApiCallback<Void>() { @Override public void onSuccess(Void info) { urlPreviewPreference.setChecked(mSession.isURLPreviewEnabled()); hideLoadingView(); } private void onError(String errorMessage) { if (null != getActivity()) { Toast.makeText(getActivity(), errorMessage, Toast.LENGTH_SHORT).show(); } onSuccess(null); } @Override public void onNetworkError(Exception e) { onError(e.getLocalizedMessage()); } @Override public void onMatrixError(MatrixError e) { onError(e.getLocalizedMessage()); } @Override public void onUnexpectedError(Exception e) { onError(e.getLocalizedMessage()); } }); } return false; } }); // push rules for (String resourceText : mPushesRuleByResourceId.keySet()) { final Preference preference = findPreference(resourceText); if (null != preference) { if (preference instanceof CheckBoxPreference) { preference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValueAsVoid) { // on some old android APIs, // the callback is called even if there is no user interaction // so the value will be checked to ensure there is really no update. onPushRuleClick(preference.getKey(), (boolean) newValueAsVoid); return true; } }); } else if (preference instanceof BingRulePreference) { final BingRulePreference bingRulePreference = (BingRulePreference) preference; bingRulePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { new AlertDialog.Builder(getActivity()).setSingleChoiceItems( bingRulePreference.getBingRuleStatuses(), bingRulePreference.getRuleStatusIndex(), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface d, int index) { BingRule rule = bingRulePreference.createRule(index); d.cancel(); if (null != rule) { displayLoadingView(); mSession.getDataHandler().getBingRulesManager().updateRule( bingRulePreference.getRule(), rule, new BingRulesManager.onBingRuleUpdateListener() { private void onDone() { refreshDisplay(); hideLoadingView(); } @Override public void onBingRuleUpdateSuccess() { onDone(); } @Override public void onBingRuleUpdateFailure( String errorMessage) { if (null != getActivity()) { Toast.makeText(getActivity(), errorMessage, Toast.LENGTH_SHORT).show(); } onDone(); } }); } } }).show(); return true; } }); } } } // background sync tuning settings // these settings are useless and hidden if the app is registered to the GCM push service final GcmRegistrationManager gcmMgr = Matrix.getInstance(appContext).getSharedGCMRegistrationManager(); if (gcmMgr.useGCM() && gcmMgr.hasRegistrationToken()) { // Hide the section PreferenceScreen preferenceScreen = getPreferenceScreen(); PreferenceCategory backgroundSyncCategory = (PreferenceCategory) findPreference( PreferencesManager.SETTINGS_BACKGROUND_SYNC_PREFERENCE_KEY); PreferenceCategory backgroundSyncDivider = (PreferenceCategory) findPreference( PreferencesManager.SETTINGS_BACKGROUND_SYNC_DIVIDER_PREFERENCE_KEY); preferenceScreen.removePreference(backgroundSyncDivider); preferenceScreen.removePreference(backgroundSyncCategory); } else { mSyncRequestTimeoutPreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_SET_SYNC_TIMEOUT_PREFERENCE_KEY); mSyncRequestDelayPreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_SET_SYNC_DELAY_PREFERENCE_KEY); final CheckBoxPreference useBackgroundSyncPref = (CheckBoxPreference) findPreference( PreferencesManager.SETTINGS_ENABLE_BACKGROUND_SYNC_PREFERENCE_KEY); if (null != useBackgroundSyncPref) { final GcmRegistrationManager.ThirdPartyRegistrationListener listener = new GcmRegistrationManager.ThirdPartyRegistrationListener() { @Override public void onThirdPartyRegistered() { hideLoadingView(); } @Override public void onThirdPartyRegistrationFailed() { hideLoadingView(); } @Override public void onThirdPartyUnregistered() { hideLoadingView(); } @Override public void onThirdPartyUnregistrationFailed() { hideLoadingView(); } }; if (null != useBackgroundSyncPref) { useBackgroundSyncPref.setChecked(gcmMgr.isBackgroundSyncAllowed()); useBackgroundSyncPref .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object aNewValue) { final boolean newValue = (boolean) aNewValue; if (newValue != gcmMgr.isBackgroundSyncAllowed()) { gcmMgr.setBackgroundSyncAllowed(newValue); } displayLoadingView(); Matrix.getInstance(VectorSettingsPreferencesFragment.this.getActivity()) .getSharedGCMRegistrationManager().forceSessionsRegistration(listener); return true; } }); } } } mUserSettingsCategory = (PreferenceCategory) findPreference( PreferencesManager.SETTINGS_USER_SETTINGS_PREFERENCE_KEY); mContactSettingsCategory = (PreferenceCategory) findPreference( PreferencesManager.SETTINGS_CONTACT_PREFERENCE_KEYS); mPushersSettingsCategory = (PreferenceCategory) findPreference( PreferencesManager.SETTINGS_NOTIFICATIONS_TARGETS_PREFERENCE_KEY); mPushersSettingsDivider = (PreferenceCategory) findPreference( PreferencesManager.SETTINGS_NOTIFICATIONS_TARGET_DIVIDER_PREFERENCE_KEY); mIgnoredUserSettingsCategory = (PreferenceCategory) findPreference( PreferencesManager.SETTINGS_IGNORED_USERS_PREFERENCE_KEY); mIgnoredUserSettingsCategoryDivider = (PreferenceCategory) findPreference( PreferencesManager.SETTINGS_IGNORE_USERS_DIVIDER_PREFERENCE_KEY); mDevicesListSettingsCategory = (PreferenceCategory) findPreference( PreferencesManager.SETTINGS_DEVICES_LIST_PREFERENCE_KEY); mDevicesListSettingsCategoryDivider = (PreferenceCategory) findPreference( PreferencesManager.SETTINGS_DEVICES_DIVIDER_PREFERENCE_KEY); mCryptographyCategory = (PreferenceCategory) findPreference( PreferencesManager.SETTINGS_CRYPTOGRAPHY_PREFERENCE_KEY); mCryptographyCategoryDivider = (PreferenceCategory) findPreference( PreferencesManager.SETTINGS_CRYPTOGRAPHY_DIVIDER_PREFERENCE_KEY); mLabsCategory = (PreferenceCategory) findPreference(PreferencesManager.SETTINGS_LABS_PREFERENCE_KEY); mGroupsFlairCategory = (PreferenceCategory) findPreference(PreferencesManager.SETTINGS_GROUPS_FLAIR_KEY); // preference to start the App info screen, to facilitate App permissions access Preference applicationInfoLInkPref = findPreference(APP_INFO_LINK_PREFERENCE_KEY); applicationInfoLInkPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { if (null != getActivity()) { Intent intent = new Intent(); intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Uri uri = Uri.fromParts("package", appContext.getPackageName(), null); intent.setData(uri); getActivity().getApplicationContext().startActivity(intent); } return true; } }); // Contacts setContactsPreferences(); // user interface preferences setUserInterfacePreferences(); final CheckBoxPreference useCryptoPref = (CheckBoxPreference) findPreference( PreferencesManager.SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_PREFERENCE_KEY); final Preference cryptoIsEnabledPref = findPreference( PreferencesManager.SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_IS_ACTIVE_PREFERENCE_KEY); cryptoIsEnabledPref.setEnabled(false); if (!mSession.isCryptoEnabled()) { useCryptoPref.setChecked(false); mLabsCategory.removePreference(cryptoIsEnabledPref); } else { mLabsCategory.removePreference(useCryptoPref); } useCryptoPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValueAsVoid) { if (TextUtils.isEmpty(mSession.getCredentials().deviceId)) { new AlertDialog.Builder(getActivity()) .setMessage(R.string.room_settings_labs_end_to_end_warnings) .setPositiveButton(R.string.logout, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); CommonActivityUtils.logout(getActivity()); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); useCryptoPref.setChecked(false); } }).setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { dialog.dismiss(); useCryptoPref.setChecked(false); } }).create().show(); } else { boolean newValue = (boolean) newValueAsVoid; if (mSession.isCryptoEnabled() != newValue) { displayLoadingView(); mSession.enableCrypto(newValue, new ApiCallback<Void>() { private void refresh() { if (null != getActivity()) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { hideLoadingView(); useCryptoPref.setChecked(mSession.isCryptoEnabled()); if (mSession.isCryptoEnabled()) { mLabsCategory.removePreference(useCryptoPref); mLabsCategory.addPreference(cryptoIsEnabledPref); } } }); } } @Override public void onSuccess(Void info) { useCryptoPref.setEnabled(false); refresh(); } @Override public void onNetworkError(Exception e) { useCryptoPref.setChecked(false); } @Override public void onMatrixError(MatrixError e) { useCryptoPref.setChecked(false); } @Override public void onUnexpectedError(Exception e) { useCryptoPref.setChecked(false); } }); } } return true; } }); // SaveMode Managment final CheckBoxPreference dataSaveModePref = (CheckBoxPreference) findPreference( PreferencesManager.SETTINGS_DATA_SAVE_MODE_PREFERENCE_KEY); dataSaveModePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { List<MXSession> sessions = Matrix.getMXSessions(getActivity()); for (MXSession session : sessions) { session.setUseDataSaveMode((boolean) newValue); } return true; } }); // Analytics tracking managment final CheckBoxPreference useAnalyticsModePref = (CheckBoxPreference) findPreference( PreferencesManager.SETTINGS_USE_ANALYTICS_KEY); // On if the analytics tracking is activated useAnalyticsModePref.setChecked(PreferencesManager.useAnalytics(appContext)); useAnalyticsModePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { PreferencesManager.setUseAnalytics(appContext, (boolean) newValue); return true; } }); // Rageshake Managment final CheckBoxPreference useRageShakeModePref = (CheckBoxPreference) findPreference( PreferencesManager.SETTINGS_USE_RAGE_SHAKE_KEY); final boolean mIsUsedRageShake = PreferencesManager.useRageshake(appContext); useRageShakeModePref.setChecked(mIsUsedRageShake); useRageShakeModePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { PreferencesManager.setUseRageshake(appContext, (boolean) newValue); return true; } }); // deactivate account EditTextPreference deactivateAccountPref = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_DEACTIVATE_ACCOUNT_KEY); if (null != deactivateAccountPref) { deactivateAccountPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { startActivity(DeactivateAccountActivity.Companion.getIntent(getActivity())); return false; } }); } addButtons(); refreshPushersList(); refreshEmailsList(); refreshPhoneNumbersList(); refreshIgnoredUsersList(); refreshDevicesList(); refreshGroupFlairsList(); }
From source file:com.orbar.pxdemo.ImageView.FivePXImageFragment.java
private void processLike() { mLikeImage = new LikeImage(getActivity(), mFiveZeroZeroImageAPIBuilder, mLoginManager, mFiveZeroZeroImageBean);/*from w w w .ja va2 s. com*/ mLikeImage.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:com.orbar.pxdemo.ImageView.FivePXImageFragment.java
private void processFavorite() { mFavoriteImage = new FavoriteImage(getActivity(), mFiveZeroZeroImageAPIBuilder, mLoginManager, mFiveZeroZeroImageBean);//w ww . j a v a2 s . c o m mFavoriteImage.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:org.thoughtcrime.securesms.conversation.ConversationActivity.java
@Override public void onActivityResult(final int reqCode, int resultCode, Intent data) { Log.i(TAG, "onActivityResult called: " + reqCode + ", " + resultCode + " , " + data); super.onActivityResult(reqCode, resultCode, data); if ((data == null && reqCode != TAKE_PHOTO && reqCode != SMS_DEFAULT) || (resultCode != RESULT_OK && reqCode != SMS_DEFAULT)) { updateLinkPreviewState();//from w w w. j a va 2s .c o m return; } switch (reqCode) { case PICK_DOCUMENT: setMedia(data.getData(), MediaType.DOCUMENT); break; case PICK_AUDIO: setMedia(data.getData(), MediaType.AUDIO); break; case PICK_CONTACT: if (isSecureText && !isSmsForced()) { openContactShareEditor(data.getData()); } else { addAttachmentContactInfo(data.getData()); } break; case GET_CONTACT_DETAILS: sendSharedContact(data.getParcelableArrayListExtra(ContactShareEditActivity.KEY_CONTACTS)); break; case GROUP_EDIT: recipient = Recipient.from(this, data.getParcelableExtra(GroupCreateActivity.GROUP_ADDRESS_EXTRA), true); recipient.addListener(this); titleView.setTitle(glideRequests, recipient); NotificationChannels.updateContactChannelName(this, recipient); setBlockedUserState(recipient, isSecureText, isDefaultSms); supportInvalidateOptionsMenu(); break; case TAKE_PHOTO: if (attachmentManager.getCaptureUri() != null) { setMedia(attachmentManager.getCaptureUri(), MediaType.IMAGE); } break; case ADD_CONTACT: recipient = Recipient.from(this, recipient.getAddress(), true); recipient.addListener(this); fragment.reloadList(); break; case PICK_LOCATION: SignalPlace place = new SignalPlace(PlacePicker.getPlace(data, this)); attachmentManager.setLocation(place, getCurrentMediaConstraints()); break; case PICK_GIF: setMedia(data.getData(), MediaType.GIF, data.getIntExtra(GiphyActivity.EXTRA_WIDTH, 0), data.getIntExtra(GiphyActivity.EXTRA_HEIGHT, 0)); break; case SMS_DEFAULT: initializeSecurity(isSecureText, isDefaultSms); break; case MEDIA_SENDER: long expiresIn = recipient.getExpireMessages() * 1000L; int subscriptionId = sendButton.getSelectedTransport().getSimSubscriptionId().or(-1); boolean initiating = threadId == -1; TransportOption transport = data.getParcelableExtra(MediaSendActivity.EXTRA_TRANSPORT); String message = data.getStringExtra(MediaSendActivity.EXTRA_MESSAGE); SlideDeck slideDeck = new SlideDeck(); if (transport == null) { throw new IllegalStateException("Received a null transport from the MediaSendActivity."); } sendButton.setTransport(transport); List<Media> mediaList = data.getParcelableArrayListExtra(MediaSendActivity.EXTRA_MEDIA); for (Media mediaItem : mediaList) { if (MediaUtil.isVideoType(mediaItem.getMimeType())) { slideDeck .addSlide(new VideoSlide(this, mediaItem.getUri(), 0, mediaItem.getCaption().orNull())); } else if (MediaUtil.isGif(mediaItem.getMimeType())) { slideDeck.addSlide(new GifSlide(this, mediaItem.getUri(), 0, mediaItem.getWidth(), mediaItem.getHeight(), mediaItem.getCaption().orNull())); } else if (MediaUtil.isImageType(mediaItem.getMimeType())) { slideDeck.addSlide(new ImageSlide(this, mediaItem.getUri(), 0, mediaItem.getWidth(), mediaItem.getHeight(), mediaItem.getCaption().orNull())); } else { Log.w(TAG, "Asked to send an unexpected mimeType: '" + mediaItem.getMimeType() + "'. Skipping."); } } final Context context = ConversationActivity.this.getApplicationContext(); sendMediaMessage(transport.isSms(), message, slideDeck, Collections.emptyList(), Collections.emptyList(), expiresIn, subscriptionId, initiating) .addListener(new AssertedSuccessListener<Void>() { @Override public void onSuccess(Void result) { AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> { Stream.of(slideDeck.getSlides()).map(Slide::getUri).withoutNulls() .filter(BlobProvider::isAuthority) .forEach(uri -> BlobProvider.getInstance().delete(context, uri)); }); } }); break; } }
From source file:gr.ioanpier.auth.users.memorypaintings.MainActivityFragment.java
/** * Displays a ProgressDialog while the images are still being loaded. *//* w w w.j ava 2s.c om*/ private void instantiateLoadingBar() { AsyncTask<Void, Integer, Void> progressDialogAsync = new AsyncTask<Void, Integer, Void>() { private ProgressDialog progDialog; @Override protected void onPreExecute() { super.onPreExecute(); progDialog = new ProgressDialog(getActivity()); progDialog.setMessage(getString(R.string.loading_bar_message)); progDialog.show(); } @Override protected Void doInBackground(Void... voids) { boolean loading = true; while (loading) { try { Thread.sleep(250); } catch (InterruptedException e) { } synchronized (numberOfBitmapWorkerTasksLock) { if (numberOfBitmapWorkerTasks == 0) { loading = false; } } } return null; } @Override protected void onPostExecute(Void aVoid) { super.onPostExecute(aVoid); progDialog.dismiss(); } }; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) progressDialogAsync.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); else progressDialogAsync.execute(); }
From source file:org.thoughtcrime.securesms.conversation.ConversationFragment.java
private void handleSaveAttachment(final MediaMmsMessageRecord message) { SaveAttachmentTask.showWarningDialog(getActivity(), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { List<SaveAttachmentTask.Attachment> attachments = Stream.of(message.getSlideDeck().getSlides()) .filter(s -> s.getUri() != null && (s.hasImage() || s.hasVideo() || s.hasAudio() || s.hasDocument())) .map(s -> new SaveAttachmentTask.Attachment(s.getUri(), s.getContentType(), message.getDateReceived(), s.getFileName().orNull())) .toList();//from w ww . j a v a 2s. c o m if (!Util.isEmpty(attachments)) { SaveAttachmentTask saveTask = new SaveAttachmentTask(getActivity()); saveTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, attachments.toArray(new SaveAttachmentTask.Attachment[0])); return; } Log.w(TAG, "No slide with attachable media found, failing nicely."); Toast.makeText(getActivity(), getResources().getQuantityString( R.plurals.ConversationFragment_error_while_saving_attachments_to_sd_card, 1), Toast.LENGTH_LONG).show(); } }); }
From source file:com.smarttaxi.driver.model.WebServiceModel.java
@SuppressLint("NewApi") private static HttpAsyncTask executeAsyncTask(HttpAsyncTask httpAsyncTask) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { return (HttpAsyncTask) httpAsyncTask.execute(); } else {//from ww w .ja v a 2 s .c o m return (HttpAsyncTask) httpAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } }
From source file:systems.byteswap.publicstream.MainActivity.java
/** listener for download item clicks **/ public void programDownloadClickListener(final ORFParser.ORFProgram child) { Toast.makeText(getBaseContext(), "Download: " + child.shortTitle, Toast.LENGTH_SHORT).show(); //increment the download notification id for each download (it is reset if the app is completely closed) currentDownloadNotificationId++;//from w w w.j a v a2 s.c o m //store the current id to the fragment dataFragment.setCurrentDownloadNotificationId(currentDownloadNotificationId); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) new DownloadProgramTask(currentDownloadNotificationId).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, child); else new DownloadProgramTask(currentDownloadNotificationId).execute(child); }
From source file:gov.cdc.epiinfo.RecordList.java
private void editRecord(long id) { Cursor c = mDbHelper.fetchRecord(id); AppManager.SetCurrentDatabase(mDbHelper); c.moveToPosition(0);/*from w ww . j av a 2 s. c o m*/ waitDialog = ProgressDialog.show(this, getString(R.string.loading_form), getString(R.string.please_wait), true); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); boolean useInterviewMode = sharedPref.getBoolean("interview", false) || formMetadata.IsInterviewForm; Intent i; if (useInterviewMode) { i = new Intent(this, Interviewer.class); } else { i = new Intent(this, RecordEditor.class); } i.putExtra(EpiDbHelper.KEY_ROWID, id); i.putExtra(EpiDbHelper.GUID, c.getString(c.getColumnIndexOrThrow(EpiDbHelper.GUID))); for (int x = 0; x < formMetadata.DataFields.size(); x++) { if (formMetadata.DataFields.get(x).getType().equals("10") || formMetadata.DataFields.get(x).getType().equals("11") || formMetadata.DataFields.get(x).getType().equals("12") || formMetadata.DataFields.get(x).getType().equals("18") || formMetadata.DataFields.get(x).getType().equals("19")) { String fieldName = formMetadata.DataFields.get(x).getName(); int columnIndex = c.getColumnIndexOrThrow(fieldName); int value = c.getInt(columnIndex); i.putExtra(fieldName, value); } else if (formMetadata.DataFields.get(x).getType().equals("17")) { if (formMetadata.DataFields.get(x).getListValues().size() > 100) { String fieldName = formMetadata.DataFields.get(x).getName(); int columnIndex = c.getColumnIndexOrThrow(fieldName); String value = c.getString(columnIndex); i.putExtra(fieldName, value); } else { String fieldName = formMetadata.DataFields.get(x).getName(); int columnIndex = c.getColumnIndexOrThrow(fieldName); int value = c.getInt(columnIndex); i.putExtra(fieldName, value); } } else if (formMetadata.DataFields.get(x).getType().equals("5")) { String fieldName = formMetadata.DataFields.get(x).getName(); int columnIndex = c.getColumnIndexOrThrow(fieldName); double value = c.getDouble(columnIndex); i.putExtra(fieldName, value); } else { String fieldName = formMetadata.DataFields.get(x).getName(); int columnIndex = c.getColumnIndexOrThrow(fieldName); String value = c.getString(columnIndex); i.putExtra(fieldName, value); } } new PreCompiledLoader().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, i); }
From source file:com.marianhello.cordova.bgloc.LocationUpdateService.java
private void schedulePostLocations() { PostLocationTask task = new LocationUpdateService.PostLocationTask(); Log.d(TAG, "beforeexecute " + task.getStatus()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); else/* w ww. j av a2 s.c o m*/ task.execute(); Log.d(TAG, "afterexecute " + task.getStatus()); }