android.support.v4.app.FragmentActivity Java Examples

The following examples show how to use android.support.v4.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: RemoteDialog.java    From DanDanPlayForAndroid with MIT License 6 votes vote down vote up
public RemoteDialog(@NonNull Context context) {
    super(context, R.style.Dialog);
    this.activity = (FragmentActivity) context;
    setContentView(R.layout.dialog_remote);
    ButterKnife.bind(this);

    ipEditEt.setHint("IP地址");
    portEditEt.setHint("端口");
    authEditEt.setHint("API密钥(可为空)");

    String remoteLoginData = AppConfig.getInstance().getRemoteLoginData();
    if (!StringUtils.isEmpty(remoteLoginData)){

        String[] loginData = remoteLoginData.split(";");
        if (loginData.length != 3) return;

        ipEditEt.setText(loginData[0]);
        portEditEt.setText(loginData[1]);
        authEditEt.setText(loginData[2].trim());
    }
}
 
Example #2
Source File: SwipeBackLayout.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
public void attachToActivity(FragmentActivity activity) {
    mActivity = activity;
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{
            android.R.attr.windowBackground
    });
    int background = a.getResourceId(0, 0);
    a.recycle();

    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
    decor.removeView(decorChild);
    addView(decorChild);
    setContentView(decorChild);
    decor.addView(this);
}
 
Example #3
Source File: BaseAppLockFragment.java    From MobileGuard with MIT License 6 votes vote down vote up
/**
 * distribute the apps and refresh ListView
 *
 * @param context
 * @param appsInfo
 */
private void initAppsAndRefreshUi(final FragmentActivity context, final List<AppInfoBean> appsInfo) {
    // refresh ui need run on ui thread
    // and remember the change data should'n in background thread
    context.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            // clear data
            apps.clear();
            // distribute apps
            AppLockDao dao = new AppLockDao(context);
            for (AppInfoBean app : appsInfo) {
                // if in locked list
                if (isNeededApp(dao, app.getPackageName())) {
                    // add to locked list
                    apps.add(app);
                }
            }
            // notify update ListView
            adapter.notifyDataSetChanged();
            // hide loading bar
            pvLoading.setVisibility(View.GONE);
        }
    });
}
 
Example #4
Source File: XAsyncTask.java    From Alibaba-Android-Certification with MIT License 6 votes vote down vote up
@Override
protected void  onPostExecute(Result o) {
    Context context=mContextWeakReference.get();
    //如果启动绑定生命周期,则Activity被销毁时,不再回调
    if(mAsyncTaskImpl.isBindLifeCycle()){
        if (context != null) {
            if(context instanceof FragmentActivity){
                boolean isDestory=((FragmentActivity) context).getSupportFragmentManager().isDestroyed();
                if(!isDestory){
                    mAsyncTaskImpl.onPostExecute(context,o);
                }
            }else{//其他类型不处理,如ApplicationContext
                mAsyncTaskImpl.onPostExecute(context,o);
            }
        }
    }else{
        mAsyncTaskImpl.onPostExecute(context,o);
    }
}
 
Example #5
Source File: Ui.java    From spark-setup-android with Apache License 2.0 6 votes vote down vote up
public static void fadeViewVisibility(FragmentActivity activity, int viewId, final boolean show) {
    // Fade-in the progress spinner.
    int shortAnimTime = activity.getResources().getInteger(
            android.R.integer.config_shortAnimTime);
    final View progressView = Ui.findView(activity, viewId);
    progressView.setVisibility(View.VISIBLE);
    progressView.animate()
            .setDuration(shortAnimTime)
            .alpha(show ? 1 : 0)
            .setListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                    progressView.setVisibility(show ? View.VISIBLE : View.GONE);
                }
            });
}
 
Example #6
Source File: OpenAsDialog.java    From rcloneExplorer with MIT License 6 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    if (savedInstanceState != null) {
        isDarkTheme = savedInstanceState.getBoolean(SAVED_IS_DARK_THEME);
        fileItem = savedInstanceState.getParcelable(SAVED_FILE_ITEM);
    }

    listener = (OnClickListener) getParentFragment();

    AlertDialog.Builder builder;

    if (isDarkTheme) {
        builder = new AlertDialog.Builder(context, R.style.DarkDialogTheme);
    } else {
        builder = new AlertDialog.Builder(context);
    }
    LayoutInflater inflater = ((FragmentActivity)context).getLayoutInflater();
    view = inflater.inflate(R.layout.dialog_open_as, null);
    setListeners();
    builder.setView(view);
    return builder.create();
}
 
Example #7
Source File: Util.java    From UETool with MIT License 6 votes vote down vote up
@Nullable
public static Fragment getCurrentFragment(View targetView) {

    Activity activity = UETool.getInstance().getTargetActivity();
    if (activity instanceof FragmentActivity) {
        List<Fragment> fragments = collectVisibleFragment(((FragmentActivity) activity).getSupportFragmentManager());
        for (int i = fragments.size() - 1; i >= 0; i--) {
            Fragment fragment = fragments.get(i);
            if (findTargetView(fragment.getView(), targetView)) {
                return fragment;
            }
        }
    }

    return null;
}
 
Example #8
Source File: AddressOfColdFragmentListAdapter.java    From bither-android with Apache License 2.0 6 votes vote down vote up
public AddressOfColdFragmentListAdapter(FragmentActivity activity,
                                        List<Address> privates, ColdAddressFragmentHDMListItemView.RequestHDMServerQrCodeDelegate requestHDMServerQrCodeDelegate) {
    this.activity = activity;
    this.privates = privates;
    this.requestHDMServerQrCodeDelegate = requestHDMServerQrCodeDelegate;
    if (AddressManager.getInstance().hasHDAccountCold()) {
        hdAccountCold = AddressManager.getInstance().getHDAccountCold();
    } else {
        hdAccountCold = null;
    }
    if (AddressManager.getInstance().hasBitpieHDAccountCold()) {
        bitpieHDAccountCold = AddressManager.getInstance().getBitpieHDAccountCold();
    } else {
        bitpieHDAccountCold = null;
    }
    if (EnterpriseHDMSeed.hasSeed()) {
        enterpriseHDMSeed = EnterpriseHDMSeed.seed();
    } else {
        enterpriseHDMSeed = null;
    }
}
 
Example #9
Source File: AnnotationFragmentManager.java    From AndroidUnitTest with Apache License 2.0 6 votes vote down vote up
public void addToActivity(@NonNull Object target, Fragment fragment) {
    String tag = null;
    for (Field fragmentField : fragmentFields) {
        Fragment fragmentOfField = (Fragment) new FieldReader(target, fragmentField).read();
        if (fragment == fragmentOfField) {
            RFragment fragmentAnnotation = fragmentField.getAnnotation(RFragment.class);
            tag = fragmentAnnotation.tag();
        }
    }
    if (tag == null || tag.isEmpty()) {
        tag = fragment.getClass().toString();
    }

    ControllerActivity controllerActivity = getAndroidUnitTest().activity();
    //if no activity is create, the default activity manager behaviour is to create one
    if (controllerActivity.get() == null) {
        controllerActivity.createAndInitActivity(FragmentActivity.class, null);
        controllerActivity.setActivityState(ActivityState.CREATED);
    }

    AnnotationFragmentManager.addToActivity(getActivity(), fragment, tag);
}
 
Example #10
Source File: ErrorDialogManager.java    From KUtils with Apache License 2.0 5 votes vote down vote up
public static void attachTo(Activity activity, Object executionScope, boolean finishAfterDialog,
        Bundle argumentsForErrorDialog) {
    FragmentManager fm = ((FragmentActivity) activity).getSupportFragmentManager();
    SupportManagerFragment fragment = (SupportManagerFragment) fm.findFragmentByTag(TAG_ERROR_DIALOG_MANAGER);
    if (fragment == null) {
        fragment = new SupportManagerFragment();
        fm.beginTransaction().add(fragment, TAG_ERROR_DIALOG_MANAGER).commit();
        fm.executePendingTransactions();
    }
    fragment.finishAfterDialog = finishAfterDialog;
    fragment.argumentsForErrorDialog = argumentsForErrorDialog;
    fragment.executionScope = executionScope;
}
 
Example #11
Source File: Utility.java    From iBeebo with GNU General Public License v3.0 5 votes vote down vote up
public static void forceShowDialog(FragmentActivity activity, DialogFragment dialogFragment) {
    try {
        dialogFragment.show(activity.getSupportFragmentManager(), "");
        activity.getSupportFragmentManager().executePendingTransactions();
    } catch (Exception ignored) {

    }
}
 
Example #12
Source File: AnnouncementListOfEachCourseFragment.java    From PKUCourses with GNU General Public License v3.0 5 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    LinearLayout linearLayout = (LinearLayout) inflater.inflate(R.layout.fragment_announcement_list, container, false);
    // 查找xml文件中的对象并保存进Java变量
    mRecyclerView = linearLayout.findViewById(R.id.recycler_announcement_list);
    mAnnouncementListSwipeContainer = linearLayout.findViewById(R.id.announcement_swipe_container);

    // 设置动画
    LayoutAnimationController animation = AnimationUtils.loadLayoutAnimation(getContext(), R.anim.layout_animation_fall_down);
    mAnnouncementListSwipeContainer.setLayoutAnimation(animation);
    // 设置刷新的监听类为此类(监听函数onRefresh)
    mAnnouncementListSwipeContainer.setOnRefreshListener(this);
    mAnnouncementListSwipeContainer.setColorSchemeColors(getResources().getColor(R.color.colorPrimary), getResources().getColor(R.color.colorAccent));

    FragmentActivity fa = getActivity();
    // 为了消除编译器Warning,需要判断一下是不是null,其实这基本上不可能出现null
    if (fa == null) {
        return linearLayout;
    }

    // SharedPreferences sharedPreferences = fa.getSharedPreferences("pinnedAnnouncementList", Context.MODE_PRIVATE);
    adapter = new AnnouncementListOfEachCourseAdapter(new ArrayList<AnnouncementInfo>(), this);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    mRecyclerView.setAdapter(adapter);
    courseId = getActivity().getIntent().getStringExtra("CourseId");

    // 显示Loading的小动画,并在后台读取课程列表
    showLoading(true);
    mLoadingTask = new AnnouncementLoadingTask();
    mLoadingTask.execute((Void) null);

    return linearLayout;
}
 
Example #13
Source File: MyGradeFragment.java    From PKUCourses with GNU General Public License v3.0 5 votes vote down vote up
private void saveCachedCourseList(String rootNodeStr) throws Exception {
    FragmentActivity fa = getActivity();
    if (fa == null) {
        throw new Exception("Unknown Error: Null getActivity()!");
    }
    SharedPreferences sharedPreferences = fa.getSharedPreferences("cached_xml", Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putString("course_list_str", rootNodeStr);
    editor.apply();
}
 
Example #14
Source File: AnnouncementBodyFragment.java    From PKUCourses with GNU General Public License v3.0 5 votes vote down vote up
private void saveCachedAnnouncementsList(String rootNodeStr) throws Exception {
    FragmentActivity fa = getActivity();
    if (fa == null) {
        throw new Exception("Unknown Error: Null getActivity()!");
    }
    SharedPreferences sharedPreferences = fa.getSharedPreferences("cached_xml", Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putString("announcement_list_str", rootNodeStr);
    editor.apply();
}
 
Example #15
Source File: RequestManagerRetriever.java    From ImmersionBar with Apache License 2.0 5 votes vote down vote up
/**
 * Get immersion bar.
 *
 * @param activity the activity
 * @return the immersion bar
 */
public ImmersionBar get(Activity activity) {
    checkNotNull(activity, "activity is null");
    String tag = mTag + System.identityHashCode(activity);
    if (activity instanceof FragmentActivity) {
        return getSupportFragment(((FragmentActivity) activity).getSupportFragmentManager(), tag).get(activity);
    } else {
        return getFragment(activity.getFragmentManager(), tag).get(activity);
    }
}
 
Example #16
Source File: UserApp.java    From userapp-android with MIT License 5 votes vote down vote up
public Session(FragmentActivity activity, UserApp.Session.StatusCallback callback) {
	this.activity = activity;
	this.sharedPreferences = this.activity.getSharedPreferences(UserApp.PREFERENCE_KEY, Context.MODE_PRIVATE);
	
	// Load App Id from AndroidManifest.xml
	this.api = new UserAppClient.API(UserApp.getAppId(this.activity));
	
	if (callback != null) {
		this.addCallback(callback);
	}
}
 
Example #17
Source File: AbsShareOnlineMusic.java    From YCAudioPlayer with Apache License 2.0 5 votes vote down vote up
private void share() {
    // 获取歌曲播放链接
    OnLineMusicModel model = OnLineMusicModel.getInstance();
    model.getMusicDownloadInfo(OnLineMusicModel.METHOD_DOWNLOAD_MUSIC,mSongId)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Consumer<DownloadInfo>() {
                @Override
                public void accept(DownloadInfo downloadInfo) throws Exception {
                    if (downloadInfo == null || downloadInfo.getBitrate() == null) {
                        onExecuteFail(null);
                        return;
                    }
                    String file_link = downloadInfo.getBitrate().getFile_link();
                    onExecuteSuccess(null);

                    ShareDetailBean shareDetailBean = new ShareDetailBean();
                    shareDetailBean.setShareType(ShareComment.ShareType.SHARE_GOODS);
                    shareDetailBean.setContent("歌曲分享");
                    shareDetailBean.setTitle(mTitle);
                    shareDetailBean.setImage(mImage);
                    shareDetailBean.setUrl(file_link);
                    ShareDialog shareDialog = new ShareDialog(mContext,shareDetailBean);
                    shareDialog.show(((FragmentActivity)mContext).getSupportFragmentManager());


                    /*Intent intent = new Intent(Intent.ACTION_SEND);
                    intent.setType("text/plain");
                    intent.putExtra(Intent.EXTRA_TEXT, mContext.getString(R.string.share_music,
                            mContext.getString(R.string.app_name), mTitle,
                            file_link));
                    mContext.startActivity(Intent.createChooser(intent,
                            mContext.getString(R.string.share)));*/
                }
            });
}
 
Example #18
Source File: MainEntryFragment.java    From misound with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mSettings = findViewbyId(R.id.main_entry_settings);
    mSettings.setOnClickListener(this);
    mEQEntry = findViewbyId(R.id.main_entry_eq);
    mEQEntry.setOnClickListener(this);
    mDiagnosis = findViewbyId(R.id.main_entry_diagnose);
    mDiagnosis.setOnClickListener(this);
    mEQEntry.setEnabled(mEqEnabled);
    mSettings.setEnabled(mSettingEnabled);

    Fragment f = getFragmentManager().findFragmentByTag(UPGRADE_TAG);
    if(f==null) {
        Fragment upgrade = new UpgradeFragment();
        getFragmentManager().beginTransaction()
                .replace(R.id.main_entry_upgrade, upgrade, UPGRADE_TAG)
                .commit();
    }

    f = getFragmentManager().findFragmentByTag(PLAYER_TAG);
    if(f==null){
        PlayerFragment pf = new PlayerFragment();
        FragmentActivity activity = getActivity();
        if(activity instanceof PlayerFragment.OnPlayerStateListener){
            pf.setStateListener((PlayerFragment.OnPlayerStateListener)activity);
        }

        getFragmentManager().beginTransaction()
                .add(R.id.main_player_container, pf, PLAYER_TAG)
                .commit();
    }
}
 
Example #19
Source File: AppLocationSupportFragment.java    From GooglePlayServiceLocationSupport with Apache License 2.0 5 votes vote down vote up
@Override
public void addApi(@NonNull Api<? extends Api.ApiOptions.NotRequiredOptions> value) {
    if (mGoogleApiClient != null)
        mGoogleApiClient.disconnect();
    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(mContext).addApi(LocationServices.API).enableAutoManage((FragmentActivity) mContext, new Random().nextInt(Integer.MAX_VALUE), this).
            addConnectionCallbacks(this).addOnConnectionFailedListener(this);
    if (!value.getName().equalsIgnoreCase(LocationServices.API.getName())) {
        addApi(value);
    }
    mGoogleApiClient = builder.build();
    if (!servicesConnected())
        mGoogleApiClient.connect();
}
 
Example #20
Source File: PermissionsHandler.java    From citra_android with GNU General Public License v3.0 5 votes vote down vote up
private static void showMessageOKCancel(final FragmentActivity activity, String message,
        DialogInterface.OnClickListener okListener)
{
  new AlertDialog.Builder(activity)
          .setMessage(message)
          .setPositiveButton(android.R.string.ok, okListener)
          .setNegativeButton(android.R.string.cancel, (dialogInterface, i) ->
                  Toast.makeText(activity, R.string.write_permission_needed, Toast.LENGTH_SHORT)
                          .show())
          .create()
          .show();
}
 
Example #21
Source File: FragmentStack.java    From fragmentstack with Apache License 2.0 5 votes vote down vote up
private FragmentStack(FragmentActivity activity, int containerId, Callback callback) {
  this.activity = activity;
  fragmentManager = activity.getSupportFragmentManager();
  this.containerId = containerId;
  this.callback = callback;

  handler = new Handler();
}
 
Example #22
Source File: ImageProxyUtils.java    From Pas with Apache License 2.0 5 votes vote down vote up
public void loadImage(FragmentActivity context, String url, ImageView imageView) {
    requestManager = Glide.with(context);
    this.mContext = context;
    this.mImage = imageView;
    this.url = url;

    loadImage(TYPE);
}
 
Example #23
Source File: FileExplorerFragment.java    From rcloneExplorer with MIT License 5 votes vote down vote up
private void showBottomBar() {
    View bottomBar = ((FragmentActivity) context).findViewById(R.id.bottom_bar);
    if (bottomBar.getVisibility() == View.VISIBLE) {
        return;
    }
    bottomBar.setVisibility(View.VISIBLE);
    Animation animation = AnimationUtils.loadAnimation(getContext(), R.anim.fade_in_animation);
    bottomBar.startAnimation(animation);
}
 
Example #24
Source File: OPFIab.java    From OPFIab with Apache License 2.0 5 votes vote down vote up
/**
 * Support version of {@link #getActivityHelper(Activity)}.
 */
@NonNull
public static ActivityIabHelper getActivityHelper(
        @NonNull final FragmentActivity fragmentActivity) {
    checkInit();
    return new ActivityIabHelperImpl(fragmentActivity, null);
}
 
Example #25
Source File: ClanUtils.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
/**
 * 登录用户是否是uid用户
 *
 * @return
 */
public static boolean isOwner(FragmentActivity context, String uid) {
    ClanApplication mApplication = (ClanApplication) context.getApplication();
    if (AppSPUtils.getUid(context).equals(uid)) {
        return true;
    }

    return false;
}
 
Example #26
Source File: IgnoreTextDialogActivity.java    From oversec with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDismiss(DialogInterface dialog) {
    super.onDismiss(dialog);
    FragmentActivity a = getActivity();
    if (a != null) {
        a.finish();
    }
}
 
Example #27
Source File: RxLazyFragment.java    From HeroVideo-master with Apache License 2.0 5 votes vote down vote up
@Override
public void onAttach(Activity activity)
{

    super.onAttach(activity);
    this.activity = (FragmentActivity) activity;
}
 
Example #28
Source File: FragmentHandlerManager.java    From SimpleProject with MIT License 5 votes vote down vote up
public FragmentHandlerManager(FragmentActivity context, Fragment parentFragment) {
	if (context == null) {
		return;
	}
	this.context = context;
	this.parentFragment = parentFragment;
}
 
Example #29
Source File: VideoGridFragment.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mVideoAdapter = new VideoListAdapter(this);

    if (savedInstanceState != null)
        setGroup(savedInstanceState.getString(KEY_GROUP));
    /* Load the thumbnailer */
    FragmentActivity activity = getActivity();
    if (activity != null)
        mThumbnailer = new Thumbnailer(activity, activity.getWindowManager().getDefaultDisplay());
}
 
Example #30
Source File: AnnotationFragmentManager.java    From AndroidUnitTest with Apache License 2.0 5 votes vote down vote up
public static void addToActivity(Activity activity, Fragment fragment, String tag) {
    if (activity instanceof FragmentActivity) {
        FragmentActivity fragmentActivity = (FragmentActivity) activity;
        fragmentActivity.getSupportFragmentManager().beginTransaction()
            .add(fragment, tag)
            .commit();
    }
}