Example usage for android.app Activity isFinishing

List of usage examples for android.app Activity isFinishing

Introduction

In this page you can find the example usage for android.app Activity isFinishing.

Prototype

public boolean isFinishing() 

Source Link

Document

Check to see whether this activity is in the process of finishing, either because you called #finish on it or someone else has requested that it finished.

Usage

From source file:com.samelody.puppetry.PresenterDelegateImpl.java

@Override
public void onViewDestroy(PassiveView view) {
    if (presenterRemoved) {
        return;// ww w.  j a  v  a2s  .c  o m
    }
    if (view instanceof Fragment) {
        Fragment fragment = (Fragment) view;
        if (fragment.getActivity().isFinishing()) {
            removePresenter();
            return;
        }
        if (fragment.isRemoving() && !saveStateCalled) {
            removePresenter();
        }
        return;
    }
    if (view instanceof Activity) {
        Activity activity = (Activity) view;
        if (activity.isFinishing()) {
            removePresenter();
        }
    }
}

From source file:com.example.app.tweetui.TimelineActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tweetui_swipe_timeline);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle(R.string.refresh_timeline_title);
    }//from w  w  w . java  2s . c o m

    // launch the app login activity when a guest user tries to favorite a Tweet
    final Callback<Tweet> actionCallback = new Callback<Tweet>() {
        @Override
        public void success(Result<Tweet> result) {
            // Intentionally blank
        }

        @Override
        public void failure(TwitterException exception) {
            if (exception instanceof TwitterAuthException) {
                startActivity(TwitterCoreMainActivity.newIntent(TimelineActivity.this));
            }
        }
    };

    final SwipeRefreshLayout swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout);
    final View emptyView = findViewById(android.R.id.empty);
    final ListView listView = (ListView) findViewById(android.R.id.list);
    listView.setEmptyView(emptyView);

    final SearchTimeline timeline = new SearchTimeline.Builder().query("#twitter").build();
    final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter.Builder(this).setTimeline(timeline)
            .setViewStyle(R.style.tw__TweetLightWithActionsStyle).setOnActionCallback(actionCallback).build();
    listView.setAdapter(adapter);

    swipeLayout.setColorSchemeResources(R.color.twitter_blue, R.color.twitter_dark);

    // set custom scroll listener to enable swipe refresh layout only when at list top
    listView.setOnScrollListener(new AbsListView.OnScrollListener() {
        boolean enableRefresh = false;

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (listView != null && listView.getChildCount() > 0) {
                // check that the first item is visible and that its top matches the parent
                enableRefresh = listView.getFirstVisiblePosition() == 0 && listView.getChildAt(0).getTop() >= 0;
            } else {
                enableRefresh = false;
            }
            swipeLayout.setEnabled(enableRefresh);
        }
    });

    // specify action to take on swipe refresh
    swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            swipeLayout.setRefreshing(true);
            adapter.refresh(new Callback<TimelineResult<Tweet>>() {
                @Override
                public void success(Result<TimelineResult<Tweet>> result) {
                    swipeLayout.setRefreshing(false);
                }

                @Override
                public void failure(TwitterException exception) {
                    swipeLayout.setRefreshing(false);
                    final Activity activity = activityRef.get();
                    if (activity != null && !activity.isFinishing()) {
                        Toast.makeText(activity, exception.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                }
            });
        }
    });
}

From source file:com.docd.purefm.ui.dialogs.PartitionInfoDialog.java

public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final Activity activity = this.getActivity();
    if (activity == null || activity.isFinishing()) {
        return null;
    }/*from w w  w .j  av  a 2 s . c  o  m*/
    //noinspection InflateParams
    mView = activity.getLayoutInflater().inflate(R.layout.dialog_partition_info, null);
    final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setIcon(ThemeUtils.getDrawableNonNull(activity, R.attr.ic_menu_info));
    builder.setTitle(R.string.menu_partition);
    builder.setView(mView);
    builder.setNeutralButton(R.string.close, null);
    return builder.create();

}

From source file:com.grottworkshop.gwsviewmodellibrary.viewmodel.ViewModelHelper.java

@SuppressWarnings("unused")
public void onDestroy(@NonNull Activity activity) {
    if (mViewModel == null) {
        //no viewmodel for this fragment
        return;//from  w  w  w .j  a  va2  s. c  o m
    }
    if (activity.isFinishing()) {
        removeViewModel(activity);
    }
}

From source file:com.groundupworks.partyphotobooth.fragments.ConfirmationFragment.java

@Override
public void onResume() {
    super.onResume();

    // Schedule auto-submission of the fragment.
    mSubmissionTimer = new Timer(AUTO_SUBMISSION_TIMER_NAME);
    mSubmissionTimer.schedule(new TimerTask() {
        @Override/*from  ww w  .j  a va 2 s.  co m*/
        public void run() {
            // Post submission request to ui thread.
            final Activity activity = getActivity();
            if (activity != null && !activity.isFinishing()) {
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        // Call to client.
                        ICallbacks callbacks = getCallbacks();
                        if (callbacks != null) {
                            callbacks.onSubmit();

                            // Clear weak reference to prevent possibility of duplicate calls.
                            mCallbacks.clear();
                        }
                    }
                });
            }
        }
    }, mAutoSubmissionTimeout);
}

From source file:com.fatelon.partyphotobooth.fragments.ConfirmationFragment.java

@Override
public void onResume() {
    super.onResume();

    // Schedule auto-submission of the fragment.
    mSubmissionTimer = new Timer(AUTO_SUBMISSION_TIMER_NAME);
    mSubmissionTimer.schedule(new TimerTask() {
        @Override//ww w  .  j  a v  a 2 s  . c o m
        public void run() {
            // Post submission request to ui thread.
            final Activity activity = getActivity();
            if (activity != null && !activity.isFinishing()) {
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {

                        // Call to client.
                        ICallbacks callbacks = getCallbacks();
                        if (callbacks != null) {
                            callbacks.onSubmit();

                            // Clear weak reference to prevent possibility of duplicate calls.
                            mCallbacks.clear();
                        }
                    }
                });
            }
        }
    }, mAutoSubmissionTimeout);
}

From source file:com.fatelon.partyphotobooth.fragments.NoticeFragment.java

@Override
public void onResume() {
    super.onResume();

    if (mIsScreenValid) {
        // Schedule auto-dismissal of the fragment.
        mDismissalTimer = new Timer(AUTO_DISMISSAL_TIMER_NAME);
        mDismissalTimer.schedule(new TimerTask() {
            @Override//from ww  w .  j a  v  a 2 s  .  c o m
            public void run() {
                // Post dismissal request to ui thread.
                final Activity activity = getActivity();
                if (activity != null && !activity.isFinishing()) {
                    activity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            // Call to client.
                            ICallbacks callbacks = getCallbacks();
                            if (callbacks != null) {
                                callbacks.onNoticeDismissRequested();
                            }
                        }
                    });
                }
            }
        }, AUTO_DISMISSAL_TIMEOUT);
    }
}

From source file:com.groundupworks.partyphotobooth.setup.fragments.ShareServicesSetupFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    final Context appContext = getActivity().getApplicationContext();

    /*/*from  ww w  . jav a2s.c om*/
     * Configure views with saved preferences and functionalize.
     */
    mFacebook.setOnClickListener(new MyLinkOnClickListener(FacebookEndpoint.class));
    mDropbox.setOnClickListener(new MyLinkOnClickListener(DropboxEndpoint.class));
    mGcp.setOnClickListener(new MyLinkOnClickListener(GoogleCloudPrintEndpoint.class));

    final PreferencesHelper preferencesHelper = new PreferencesHelper();
    boolean isChecked = preferencesHelper.getNoticeEnabled(appContext);
    mNoticeEnabled.setChecked(isChecked);
    mNoticeEnabled.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            Activity activity = getActivity();
            if (activity != null && !activity.isFinishing()) {
                preferencesHelper.storeNoticeEnabled(appContext, isChecked);
            }
        }
    });

    mNext.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // Call to client.
            ICallbacks callbacks = getCallbacks();
            if (callbacks != null) {
                callbacks.onShareServicesSetupCompleted();
            }
        }
    });
}

From source file:com.github.ppamorim.library.DraggerView.java

private void finish() {
    if (canFinish) {
        Context context = getContext();
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (!activity.isFinishing()) {
                activity.overridePendingTransition(0, android.R.anim.fade_out);
                activity.finish();/*from ww  w  .j  ava2 s .  c  o  m*/
            }
        }
    }
}

From source file:com.hannesdorfmann.mosby3.mvp.delegate.FragmentMvpDelegateImpl.java

protected boolean retainPresenterInstance() {

    Activity activity = getActivity();
    if (activity.isChangingConfigurations()) {
        return keepPresenterInstanceDuringScreenOrientationChanges;
    }/* www  .  ja v  a 2  s.  c  om*/

    if (activity.isFinishing()) {
        return false;
    }

    if (keepPresenterOnBackstack && BackstackAccessor.isFragmentOnBackStack(fragment)) {
        return true;
    }

    return !fragment.isRemoving();
}