androidx.fragment.app.FragmentActivity Java Examples

The following examples show how to use androidx.fragment.app.FragmentActivity. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ValidateUtils.java    From Android-Goldfinger with Apache License 2.0 6 votes vote down vote up
/**
 * Return list of prompt params errors. If no errors detected, list will be empty.
 */
@NonNull
static List<String> validatePromptParams(@NonNull Mode mode, @NonNull Goldfinger.PromptParams params) {
    List<String> errors = new ArrayList<>();

    if (!(params.dialogOwner() instanceof Fragment) && !(params.dialogOwner() instanceof FragmentActivity)) {
        errors.add("DialogOwner must be of instance Fragment or FragmentActivity");
    }

    if (StringUtils.isBlankOrNull(params.title())) {
        errors.add("Title is required!");
    }

    if (!params.deviceCredentialsAllowed() && StringUtils.isBlankOrNull(params.negativeButtonText())) {
        errors.add("NegativeButtonText is required!");
    }

    if (params.deviceCredentialsAllowed() && mode != Mode.AUTHENTICATION) {
        errors.add("DeviceCredentials are allowed only for Goldfinger#authenticate method.");
    }

    return errors;
}
 
Example #2
Source File: SAFUtils.java    From libcommon with Apache License 2.0 6 votes vote down vote up
/**
 * requestCodeに対応するUriへのアクセス要求を行う
 * @param activity
 * @param requestCode
 * @return 既にrequestCodeに対応するUriが存在していればそれを返す, 存在していなければパーミッション要求をしてnullを返す
 * @throws UnsupportedOperationException
 */
@Nullable
public static Uri requestPermission(
	@NonNull final FragmentActivity activity,
	final int requestCode) {

	if (BuildCheck.isLollipop()) {
		final Uri uri = getStorageUri(activity, requestCode);
		if (uri == null) {
			// requestCodeに対応するUriへのパーミッションを保持していない時は要求してnullを返す
			activity.startActivityForResult(prepareStorageAccessPermission(), requestCode);
		}
		return uri;
	} else {
		throw new UnsupportedOperationException("should be API>=21");
	}
}
 
Example #3
Source File: CommunicationActions.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
public static void startVoiceCall(@NonNull FragmentActivity activity, @NonNull Recipient recipient) {
  if (TelephonyUtil.isAnyPstnLineBusy(activity)) {
    Toast.makeText(activity,
                   R.string.CommunicationActions_a_cellular_call_is_already_in_progress,
                   Toast.LENGTH_SHORT)
         .show();
    return;
  }

  WebRtcCallService.isCallActive(activity, new ResultReceiver(new Handler(Looper.getMainLooper())) {
    @Override
    protected void onReceiveResult(int resultCode, Bundle resultData) {
      if (resultCode == 1) {
        startCallInternal(activity, recipient, false);
      } else {
        new AlertDialog.Builder(activity)
                       .setMessage(R.string.CommunicationActions_start_voice_call)
                       .setPositiveButton(R.string.CommunicationActions_call, (d, w) -> startCallInternal(activity, recipient, false))
                       .setNegativeButton(R.string.CommunicationActions_cancel, (d, w) -> d.dismiss())
                       .setCancelable(true)
                       .show();
      }
    }
  });
}
 
Example #4
Source File: ContactSelectionActivity.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void addFragment(FragmentActivity fragmentActivity, Fragment fragmentToAdd,
                               String fragmentTag) {
    FragmentManager supportFragmentManager = fragmentActivity.getSupportFragmentManager();

    FragmentTransaction fragmentTransaction = supportFragmentManager
            .beginTransaction();
    fragmentTransaction.replace(R.id.layout_child_activity, fragmentToAdd,
            fragmentTag);

    if (supportFragmentManager.getBackStackEntryCount() > 1) {
        supportFragmentManager.popBackStack();
    }
    fragmentTransaction.addToBackStack(fragmentTag);
    fragmentTransaction.commitAllowingStateLoss();
    supportFragmentManager.executePendingTransactions();
}
 
Example #5
Source File: WXTabPagerComponent.java    From CrazyDaily with Apache License 2.0 6 votes vote down vote up
@WXComponentProp(name = "titledata")
public void setData(List<String> datas) {

    if (mTabPagerAdapter == null) {
        final Context context = getContext();
        if (!(context instanceof FragmentActivity)) {
            LoggerUtil.d("context不是FragmentActivity");
            return;
        }
        final FragmentActivity activity = (FragmentActivity) context;
        mTabPagerAdapter = new TabPagerAdapter(activity.getSupportFragmentManager(), datas);
        mViewPager.setAdapter(mTabPagerAdapter);
        return;
    }
    mTabPagerAdapter.reload(datas);
}
 
Example #6
Source File: PermUtil.java    From PixImagePicker with Apache License 2.0 6 votes vote down vote up
public static void checkForCamaraWritePermissions(final FragmentActivity activity, WorkFinish workFinish) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        workFinish.onWorkFinish(true);
    } else {
        List<String> permissionsNeeded = new ArrayList<String>();
        final List<String> permissionsList = new ArrayList<String>();
        if (!addPermission(permissionsList, Manifest.permission.CAMERA, activity))
            permissionsNeeded.add("CAMERA");
        if (!addPermission(permissionsList, Manifest.permission.WRITE_EXTERNAL_STORAGE, activity))
            permissionsNeeded.add("WRITE_EXTERNAL_STORAGE");
        if (permissionsList.size() > 0) {
            activity.requestPermissions(permissionsList.toArray(new String[permissionsList.size()]),
                    REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS);
        } else {
            workFinish.onWorkFinish(true);
        }
    }
}
 
Example #7
Source File: ChromeCustomTabsTest.java    From browser-switch-android with MIT License 5 votes vote down vote up
@Test
@SdkSuppress(maxSdkVersion = 23)
public void isAvailable_whenCustomTabsAreNotSupported_returnsFalse() {
    scenario.onFragment(fragment -> {
        FragmentActivity activity = fragment.getActivity();
        assertFalse(ChromeCustomTabs.isAvailable(activity.getApplication()));
    });
}
 
Example #8
Source File: CommunicationActions.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private static void startAudioCallInternal(@NonNull FragmentActivity activity, @NonNull Recipient recipient) {
  Permissions.with(activity)
             .request(Manifest.permission.RECORD_AUDIO)
             .ifNecessary()
             .withRationaleDialog(activity.getString(R.string.ConversationActivity__to_call_s_signal_needs_access_to_your_microphone, recipient.getDisplayName(activity)),
                 R.drawable.ic_mic_solid_24)
             .withPermanentDenialDialog(activity.getString(R.string.ConversationActivity__to_call_s_signal_needs_access_to_your_microphone, recipient.getDisplayName(activity)))
             .onAllGranted(() -> {
               Intent intent = new Intent(activity, WebRtcCallService.class);
               intent.setAction(WebRtcCallService.ACTION_OUTGOING_CALL)
                     .putExtra(WebRtcCallService.EXTRA_REMOTE_PEER, new RemotePeer(recipient.getId()))
                     .putExtra(WebRtcCallService.EXTRA_OFFER_TYPE, OfferMessage.Type.AUDIO_CALL.getCode());
               activity.startService(intent);

               MessageSender.onMessageSent();

               if (FeatureFlags.profileForCalling() && recipient.resolve().getProfileKey() == null) {
                 CalleeMustAcceptMessageRequestDialogFragment.create(recipient.getId())
                                                             .show(activity.getSupportFragmentManager(), null);
               } else {
                 Intent activityIntent = new Intent(activity, WebRtcCallActivity.class);

                 activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                 activity.startActivity(activityIntent);
               }
             })
             .execute();
}
 
Example #9
Source File: BiometricAuthHelper.java    From Passbook with Apache License 2.0 5 votes vote down vote up
public BiometricAuthHelper(boolean isFirstTime, BiometricListener listener, FragmentActivity context) {
    Executor executor = ContextCompat.getMainExecutor(context);
    mBiometricPrompt = new BiometricPrompt(context, executor, this);
    this.mIsFirstTime = isFirstTime;
    mTitle = context.getString(R.string.fp_title);
    initCipher(mIsFirstTime ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE);
    if (mIsFirstTime) {
        mDesc = context.getString(R.string.fp_ask);
        mNegativeButtonText = context.getString(android.R.string.cancel);
    } else {
        mDesc = context.getString(R.string.fp_desc);
        mNegativeButtonText = context.getString(R.string.fp_use_pwd);
    }
    this.mListener = listener;
}
 
Example #10
Source File: ViewModelProviders.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@link ViewModelProvider}, which retains ViewModels while a scope of given Activity
 * is alive. More detailed explanation is in {@link ViewModel}.
 * <p>
 * It uses the given {@link Factory} to instantiate new ViewModels.
 *
 * @param activity an activity, in whose scope ViewModels should be retained
 * @param factory  a {@code Factory} to instantiate new ViewModels
 * @return a ViewModelProvider instance
 */
@NonNull
@MainThread
public static ViewModelProvider of(@NonNull FragmentActivity activity,
        @Nullable Factory factory) {
    Application application = checkApplication(activity);
    if (factory == null) {
        factory = ViewModelProvider.AndroidViewModelFactory.getInstance(application);
    }
    return new ViewModelProvider(activity.getViewModelStore(), factory);
}
 
Example #11
Source File: HomeEventsFragment.java    From intra42 with Apache License 2.0 5 votes vote down vote up
@Override
public void onItemClick(Events item) {
    BottomSheetEventDialogFragment bottomSheetDialogFragment = BottomSheetEventDialogFragment.newInstance(item);
    FragmentActivity activity = getActivity();
    if (activity != null)
        bottomSheetDialogFragment.show(activity.getSupportFragmentManager(), bottomSheetDialogFragment.getTag());
}
 
Example #12
Source File: MessageDialogFragmentV4.java    From libcommon with Apache License 2.0 5 votes vote down vote up
/**
 * ダイアログ表示のためのヘルパーメソッド
 * @param parent
 * @param requestCode
 * @param id_title
 * @param id_message
 * @param permissions
 * @return
 * @throws IllegalStateException
 */
public static MessageDialogFragmentV4 showDialog(
	@NonNull final FragmentActivity parent, final int requestCode,
	@StringRes final int id_title, @StringRes final int id_message,
	@NonNull final String[] permissions) throws IllegalStateException {

	final MessageDialogFragmentV4 dialog
		= newInstance(requestCode, id_title, id_message, permissions);
	dialog.show(parent.getSupportFragmentManager(), TAG);
	return dialog;
}
 
Example #13
Source File: FragmentBase.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FragmentActivity activity = getActivity();
    if (!(activity instanceof HelperActivityBase)) {
        throw new IllegalStateException("Cannot use this fragment without the helper activity");
    }
    mActivity = (HelperActivityBase) activity;
}
 
Example #14
Source File: BaseScene.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
public boolean isDrawersVisible() {
    FragmentActivity activity = getActivity();
    if (activity instanceof MainActivity) {
        return ((MainActivity) activity).isDrawersVisible();
    } else {
        return false;
    }
}
 
Example #15
Source File: BluetoothChatFragment.java    From connectivity-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the status on the action bar.
 *
 * @param resId a string resource ID
 */
private void setStatus(int resId) {
    FragmentActivity activity = getActivity();
    if (null == activity) {
        return;
    }
    final ActionBar actionBar = activity.getActionBar();
    if (null == actionBar) {
        return;
    }
    actionBar.setSubtitle(resId);
}
 
Example #16
Source File: Utilities.java    From call_manage with MIT License 5 votes vote down vote up
/**
 * Send sms by given phone number and message
 *
 * @param phoneNum destination phone number (where to send the sms to)
 * @param msg      the content message of the sms
 */
public static void sendSMS(FragmentActivity activity, String phoneNum, String msg) {
    if (ContextCompat.checkSelfPermission(activity, SEND_SMS) == PackageManager.PERMISSION_GRANTED) {
        try {
            SmsManager.getDefault().sendTextMessage(CallManager.getDisplayContact(activity).getMainPhoneNumber(), null, msg, null, null);
            Toast.makeText(activity, "Message Sent", Toast.LENGTH_SHORT).show();
        } catch (Exception e) {
            Toast.makeText(activity, "Oh shit I can't send the message... Sorry", Toast.LENGTH_LONG).show();
        }
    } else {
        ActivityCompat.requestPermissions(activity, new String[]{SEND_SMS}, 1);
    }
}
 
Example #17
Source File: SpyglassRobolectricRunner.java    From Spyglass with Apache License 2.0 5 votes vote down vote up
public static void startFragment(Fragment fragment, FragmentActivity activity, String tag) {
    FragmentManager fragmentManager = activity.getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.add(fragment, tag);
    fragmentTransaction.commit();
    fragmentManager.executePendingTransactions();
    activity.invalidateOptionsMenu();
}
 
Example #18
Source File: PeripheralModeFragment.java    From Bluefruit_LE_Connect_Android_V2 with MIT License 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();

    FragmentActivity activity = getActivity();
    if (activity != null) {
        activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
    }
}
 
Example #19
Source File: SceneFragment.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    view.setTag(R.id.fragment_tag, getTag());
    view.setBackgroundDrawable(AttrResources.getAttrDrawable(getContext(), android.R.attr.windowBackground));

    // Notify
    FragmentActivity activity = getActivity();
    if (activity instanceof StageActivity) {
        ((StageActivity) activity).onSceneViewCreated(this, savedInstanceState);
    }
}
 
Example #20
Source File: CreateChatFragment.java    From adamant-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    FragmentActivity activity = getActivity();
    if (activity != null) {
        String qrCode = qrCodeHelper.parseActivityResult(activity, requestCode, resultCode, data);

        if (!qrCode.isEmpty()){
            addressView.setText(qrCode);
            createChatPresenter.onClickCreateNewChat(qrCode);
            dismiss();
        }
    }

    super.onActivityResult(requestCode, resultCode, data);
}
 
Example #21
Source File: BaseScene.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
public int getDrawerLockMode(int edgeGravity) {
    FragmentActivity activity = getActivity();
    if (activity instanceof MainActivity) {
        return ((MainActivity) activity).getDrawerLockMode(edgeGravity);
    } else {
        return DrawerLayout.LOCK_MODE_UNLOCKED;
    }
}
 
Example #22
Source File: CreateChatFragment.java    From adamant-android with GNU General Public License v3.0 5 votes vote down vote up
public void scanQrCodeClick() {
    FragmentActivity activity = getActivity();
    if (activity != null) {
        Intent intent = new Intent(activity, ScanQrCodeScreen.class);
        startActivityForResult(intent, Constants.SCAN_QR_CODE_RESULT);
    }
}
 
Example #23
Source File: ProcessOwnerTest.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private FragmentActivity setupObserverOnResume() throws Throwable {
    FragmentActivity firstActivity = activityTestRule.getActivity();
    waitTillResumed(firstActivity, activityTestRule);
    addProcessObserver(mObserver);
    mObserver.mChangedState = false;
    return firstActivity;
}
 
Example #24
Source File: EasyPhotos.java    From EasyPhotos with Apache License 2.0 5 votes vote down vote up
/**
 * 提供外部预览图片(网络图片请开启网络权限)
 *
 * @param act           上下文
 * @param imageEngine   图片加载引擎
 * @param paths         图片路径集合
 * @param bottomPreview 是否显示底部预览效果
 */
public static void startPreviewPaths(FragmentActivity act, @NonNull ImageEngine imageEngine, @NonNull ArrayList<String> paths, boolean bottomPreview) {
    Setting.imageEngine = imageEngine;
    ArrayList<Photo> photos = new ArrayList<>();
    for (String path : paths) {
        Photo photo = new Photo(null, path, 0, 0, 0, 0, 0, "");
        photos.add(photo);
    }
    PreviewActivity.start(act, photos, bottomPreview);
}
 
Example #25
Source File: UpcomingAdapter.java    From cathode with Apache License 2.0 5 votes vote down vote up
public UpcomingAdapter(FragmentActivity activity, Callbacks callbacks) {
  super(activity);
  this.activity = activity;
  this.callbacks = callbacks;

  setHasStableIds(true);
}
 
Example #26
Source File: ConnectToApFragment.java    From particle-android with Apache License 2.0 5 votes vote down vote up
public static ConnectToApFragment ensureAttached(FragmentActivity activity) {
    ConnectToApFragment frag = get(activity);
    if (frag == null) {
        frag = new ConnectToApFragment();
        WorkerFragment.addFragment(activity, frag, TAG);
    }
    return frag;
}
 
Example #27
Source File: RepliesListAdapter.java    From mimi-reader with Apache License 2.0 5 votes vote down vote up
public RepliesListAdapter(final FragmentActivity activity, final String boardName, final List<ChanPost> replies, final List<OutsideLink> links, final ChanThread thread) {
    this.activity = activity;
    this.boardName = boardName;
    this.replies = replies;
    this.links = (links == null) ? new ArrayList<OutsideLink>() : links;
    this.thread = thread;
    this.inflater = LayoutInflater.from(activity);

    this.thumbUrlMap = new HashMap<>();

    this.flagUrl = MimiUtil.https() + activity.getString(R.string.flag_int_link);
    this.trollUrl = MimiUtil.https() + activity.getString(R.string.flag_pol_link);

    setupReplies();
}
 
Example #28
Source File: ProcessOwnerTest.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Test
public void testRecreation() throws Throwable {
    FragmentActivity activity = setupObserverOnResume();
    FragmentActivity recreated = TestUtils.recreateActivity(activity, activityTestRule);
    assertThat("Failed to recreate", recreated, notNullValue());
    checkProcessObserverSilent(recreated);
}
 
Example #29
Source File: ImagePicker.java    From YImagePicker with Apache License 2.0 5 votes vote down vote up
/**
 * 提供媒体相册列表
 *
 * @param activity    调用activity
 * @param mimeTypeSet 指定相册文件类型
 * @param provider    相回调
 */
public static void provideMediaSets(FragmentActivity activity,
                                    Set<MimeType> mimeTypeSet,
                                    MediaSetsDataSource.MediaSetProvider provider) {
    if (PPermissionUtils.hasStoragePermissions(activity)) {
        MediaSetsDataSource.create(activity).setMimeTypeSet(mimeTypeSet).loadMediaSets(provider);
    }
}
 
Example #30
Source File: ProcessOwnerTest.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Test
public void testNavigationToNonSupport() throws Throwable {
    FragmentActivity firstActivity = setupObserverOnResume();
    Instrumentation.ActivityMonitor monitor = new Instrumentation.ActivityMonitor(
            NonSupportActivity.class.getCanonicalName(), null, false);
    Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    instrumentation.addMonitor(monitor);

    Intent intent = new Intent(firstActivity, NonSupportActivity.class);
    firstActivity.finish();
    firstActivity.startActivity(intent);
    NonSupportActivity secondActivity = (NonSupportActivity) monitor.waitForActivity();
    assertThat("Failed to navigate", secondActivity, notNullValue());
    checkProcessObserverSilent(secondActivity);
}