Example usage for android.app Activity getLocalClassName

List of usage examples for android.app Activity getLocalClassName

Introduction

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

Prototype

@NonNull
public String getLocalClassName() 

Source Link

Document

Returns class name for this activity with the package prefix removed.

Usage

From source file:com.google.android.testing.nativedriver.server.AndroidNativeDriver.java

/**
 * Returns a string that looks like a URL that describes the current activity.
 * Each running activity is assigned a unique URL, so the URL can be used to
 * detect the starting of new activities or resuming existing activities.
 *///from   w  ww  .  j a  va  2 s  . com
@Override
public String getCurrentUrl() {
    Activity activity = context.getActivities().current();
    if (activity == null) {
        return null;
    }
    int id = context.getActivities().idOf(activity);
    if (id == Activities.NO_ID) {
        return null;
    }
    return "and-activity://" + activity.getLocalClassName() + "?id=" + id;
}

From source file:cat.ereza.customactivityoncrash.CustomActivityOnCrash.java

/**
 * Installs CustomActivityOnCrash on the application using the default error activity.
 *
 * @param context Context to use for obtaining the ApplicationContext. Must not be null.
 *//*from  w w w . ja  v a2  s .  c o  m*/
public static void install(Context context) {
    try {
        if (context == null) {
            Log.e(TAG, "Install failed: context is null!");
        } else {
            if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                Log.w(TAG,
                        "CustomActivityOnCrash will be installed, but may not be reliable in API lower than 14");
            }

            //INSTALL!
            final Thread.UncaughtExceptionHandler oldHandler = Thread.getDefaultUncaughtExceptionHandler();

            if (oldHandler != null && oldHandler.getClass().getName().startsWith(CAOC_HANDLER_PACKAGE_NAME)) {
                Log.e(TAG, "You have already installed CustomActivityOnCrash, doing nothing!");
            } else {
                if (oldHandler != null
                        && !oldHandler.getClass().getName().startsWith(DEFAULT_HANDLER_PACKAGE_NAME)) {
                    Log.e(TAG,
                            "IMPORTANT WARNING! You already have an UncaughtExceptionHandler, are you sure this is correct? If you use ACRA, Crashlytics or similar libraries, you must initialize them AFTER CustomActivityOnCrash! Installing anyway, but your original handler will not be called.");
                }

                application = (Application) context.getApplicationContext();

                //We define a default exception handler that does what we want so it can be called from Crashlytics/ACRA
                Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
                    @Override
                    public void uncaughtException(Thread thread, final Throwable throwable) {
                        Log.e(TAG,
                                "App has crashed, executing CustomActivityOnCrash's UncaughtExceptionHandler",
                                throwable);

                        if (hasCrashedInTheLastSeconds(application)) {
                            Log.e(TAG,
                                    "App already crashed in the last 2 seconds, not starting custom error activity because we could enter a restart loop. Are you sure that your app does not crash directly on init?",
                                    throwable);
                            if (oldHandler != null) {
                                oldHandler.uncaughtException(thread, throwable);
                                return;
                            }
                        } else {
                            setLastCrashTimestamp(application, new Date().getTime());

                            if (errorActivityClass == null) {
                                errorActivityClass = guessErrorActivityClass(application);
                            }

                            if (isStackTraceLikelyConflictive(throwable, errorActivityClass)) {
                                Log.e(TAG,
                                        "Your application class or your error activity have crashed, the custom activity will not be launched!");
                                if (oldHandler != null) {
                                    oldHandler.uncaughtException(thread, throwable);
                                    return;
                                }
                            } else if (launchErrorActivityWhenInBackground || !isInBackground) {

                                final Intent intent = new Intent(application, errorActivityClass);
                                StringWriter sw = new StringWriter();
                                PrintWriter pw = new PrintWriter(sw);
                                throwable.printStackTrace(pw);
                                String stackTraceString = sw.toString();

                                //Reduce data to 128KB so we don't get a TransactionTooLargeException when sending the intent.
                                //The limit is 1MB on Android but some devices seem to have it lower.
                                //See: http://developer.android.com/reference/android/os/TransactionTooLargeException.html
                                //And: http://stackoverflow.com/questions/11451393/what-to-do-on-transactiontoolargeexception#comment46697371_12809171
                                if (stackTraceString.length() > MAX_STACK_TRACE_SIZE) {
                                    String disclaimer = " [stack trace too large]";
                                    stackTraceString = stackTraceString.substring(0,
                                            MAX_STACK_TRACE_SIZE - disclaimer.length()) + disclaimer;
                                }

                                if (enableAppRestart && restartActivityClass == null) {
                                    //We can set the restartActivityClass because the app will terminate right now,
                                    //and when relaunched, will be null again by default.
                                    restartActivityClass = guessRestartActivityClass(application);
                                } else if (!enableAppRestart) {
                                    //In case someone sets the activity and then decides to not restart
                                    restartActivityClass = null;
                                }

                                String userLogString = "";
                                while (!userLogs.isEmpty()) {
                                    userLogString += userLogs.poll();
                                }

                                intent.putExtra(EXTRA_STACK_TRACE, stackTraceString);
                                intent.putExtra(EXTRA_USER_ACTION_TRACE, userLogString);
                                intent.putExtra(EXTRA_RESTART_ACTIVITY_CLASS, restartActivityClass);
                                intent.putExtra(EXTRA_SHOW_ERROR_DETAILS, showErrorDetails);
                                intent.putExtra(EXTRA_EVENT_LISTENER, eventListener);
                                intent.putExtra(EXTRA_IMAGE_DRAWABLE_ID, defaultErrorActivityDrawableId);
                                intent.setFlags(
                                        Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                                if (eventListener != null) {
                                    eventListener.onLaunchErrorActivity();
                                }
                                application.startActivity(intent);
                            }
                        }
                        final Activity lastActivity = lastActivityCreated.get();
                        if (lastActivity != null) {
                            //We finish the activity, this solves a bug which causes infinite recursion.
                            //This is unsolvable in API<14, so beware!
                            //See: https://github.com/ACRA/acra/issues/42
                            lastActivity.finish();
                            lastActivityCreated.clear();
                        }
                        killCurrentProcess();
                    }
                });
                if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    application
                            .registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() {
                                int currentlyStartedActivities = 0;
                                DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);

                                @Override
                                public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
                                    if (activity.getClass() != errorActivityClass) {
                                        // Copied from ACRA:
                                        // Ignore activityClass because we want the last
                                        // application Activity that was started so that we can
                                        // explicitly kill it off.
                                        lastActivityCreated = new WeakReference<>(activity);
                                    }
                                    userLogs.add(dateFormat.format(new Date()) + " "
                                            + activity.getLocalClassName() + " created\n");
                                }

                                @Override
                                public void onActivityStarted(Activity activity) {
                                    currentlyStartedActivities++;
                                    isInBackground = (currentlyStartedActivities == 0);
                                    //Do nothing
                                }

                                @Override
                                public void onActivityResumed(Activity activity) {
                                    userLogs.add(dateFormat.format(new Date()) + " "
                                            + activity.getLocalClassName() + " resumed\n");
                                }

                                @Override
                                public void onActivityPaused(Activity activity) {
                                    userLogs.add(dateFormat.format(new Date()) + " "
                                            + activity.getLocalClassName() + " paused\n");
                                }

                                @Override
                                public void onActivityStopped(Activity activity) {
                                    //Do nothing
                                    currentlyStartedActivities--;
                                    isInBackground = (currentlyStartedActivities == 0);
                                }

                                @Override
                                public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
                                    //Do nothing
                                }

                                @Override
                                public void onActivityDestroyed(Activity activity) {
                                    userLogs.add(dateFormat.format(new Date()) + " "
                                            + activity.getLocalClassName() + " destroyed\n");
                                }
                            });
                }

                Log.i(TAG, "CustomActivityOnCrash has been installed.");
            }
        }
    } catch (Throwable t) {
        Log.e(TAG,
                "An unknown error occurred while installing CustomActivityOnCrash, it may not have been properly initialized. Please report this as a bug if needed.",
                t);
    }
}

From source file:com.amazon.android.contentbrowser.helper.AuthHelper.java

/**
 * Handle error bundle./*www  . j  av  a2s  .c  om*/
 * TODO: Devtech 2447: Utilize logout method implemented above.
 *
 * @param extras Extras bundle.
 */
public void handleErrorBundle(Bundle extras) {

    Bundle bundle = extras.getBundle(AuthenticationConstants.ERROR_BUNDLE);
    Activity activity = mContentBrowser.getNavigator().getActiveActivity();
    Log.d(TAG, "handleErrorBundle called" + activity.getLocalClassName());
    ErrorHelper.injectErrorFragment(activity, convertAuthErrorToErrorUtils(bundle),
            (fragment, errorButtonType, errorCategory) -> {
                if (ErrorUtils.ERROR_BUTTON_TYPE.DISMISS == errorButtonType) {
                    fragment.dismiss();
                } else if (ErrorUtils.ERROR_BUTTON_TYPE.LOGOUT == errorButtonType) {
                    mIAuthentication.logout(activity, new IAuthentication.ResponseHandler() {
                        @Override
                        public void onSuccess(Bundle extras) {

                            broadcastAuthenticationStatus(false);
                            fragment.dismiss();
                        }

                        @Override
                        public void onFailure(Bundle extras) {

                            fragment.getArguments().putString(ErrorDialogFragment.ARG_ERROR_MESSAGE,
                                    activity.getResources().getString(R.string.logout_failure_message));
                        }
                    });
                }
            });
}

From source file:it.imwatch.nfclottery.dialogs.ClearWinnersDialog.java

/**
 * Clears the winner flag from all contacts in the database.
 *///from   w w w.  j  av a2s  . c o m
private void clearWinners() {
    final Activity activity = getActivity();
    if (activity == null) {
        Log.e(TAG, "Not attached to Activity: cannot clear winners in DB");
        return;
    }

    DataHelper.clearAllWinners(activity);

    if (activity instanceof MainActivity) {
        final MainActivity mainActivity = (MainActivity) activity;
        mainActivity.showCroutonNao(mainActivity.getString(R.string.info_winners_cleared), Style.INFO);
        mainActivity.updateParticipantsCount();
    } else {
        Log.e(TAG, "The parent Activity is not MainActivity! Wat is this I don't even");
        if (DEBUG)
            Log.d(TAG, "Activity class: " + activity.getLocalClassName());
        Toast.makeText(activity, activity.getString(R.string.clear_winners_failed_wrong_parent),
                Toast.LENGTH_SHORT).show();
    }
}

From source file:it.imwatch.nfclottery.dialogs.ClearDBAlertDialog.java

/**
 * Clears the database./*w  ww  . j  a  v a 2  s  .c om*/
 */
private void clearDB() {
    final Activity activity = getActivity();
    if (activity == null) {
        Log.e(TAG, "Not attached to Activity: cannot clear DB");
        return;
    }

    ContentResolver cr = activity.getContentResolver();
    cr.delete(NFCMLContent.Geeks.CONTENT_URI, null, null);

    if (activity instanceof MainActivity) {
        final MainActivity mainActivity = (MainActivity) activity;
        mainActivity.showCroutonNao(mainActivity.getString(R.string.info_db_cleared), Style.INFO);
        mainActivity.updateParticipantsCount();
    } else {
        Log.e(TAG, "The parent Activity is not MainActivity! Wat is this I don't even");
        if (DEBUG)
            Log.d(TAG, "Activity class: " + activity.getLocalClassName());
        Toast.makeText(activity, activity.getString(R.string.clear_db_failed_wrong_parent), Toast.LENGTH_SHORT)
                .show();
    }
}

From source file:se.lu.nateko.edca.BackboneSvc.java

/**
 * Method that sets the reference to the currently active Activity to which
 * results and alerts are posted.//w w  w  .j a v  a2s  .  com
 * @param activeActivity The Activity which is currently visible.
 */
public void setActiveActivity(Activity activeActivity) {
    //      Log.d(TAG, "setActiveActivity(Activity) called.");
    mActiveActivity = activeActivity;
    Log.v(TAG, "New active activity: " + activeActivity.getLocalClassName());
}

From source file:it.imwatch.nfclottery.dialogs.InsertContactDialog.java

/**
 * Check the data inserted into the form and it all the required fields are present,
 * then it adds the contact into DB/*from  ww  w.ja  v a  2 s  .c  om*/
 */
private boolean checkAndInsert() {
    final Activity activity = getActivity();
    if (activity == null) {
        Log.e(TAG, "Not attached to Activity: cannot insert contact in DB");
        return true; // We can close, there's nothing to do anyway
    }
    String email = null;
    ArrayList<String> name = new ArrayList<String>(1), organization = new ArrayList<String>(1),
            title = new ArrayList<String>(1);

    if (mNameEditText != null && mNameEditText.getText() != null) {
        name.add(mNameEditText.getText().toString());
    }

    if (mEmailEditText != null && mEmailEditText.getText() != null) {
        email = mEmailEditText.getText().toString();
    }

    if (mOrganizationEditText != null && mOrganizationEditText.getText() != null
            && TextUtils.isGraphic(mOrganizationEditText.getText())) {

        organization.add(mOrganizationEditText.getText().toString());
    }

    if (mTitleEditText != null && mTitleEditText.getText() != null
            && TextUtils.isGraphic(mTitleEditText.getText())) {
        title.add(mTitleEditText.getText().toString());
    }

    if (activity instanceof MainActivity) {
        final MainActivity mainActivity = (MainActivity) activity;

        if (!isValidEmailAddress(email)) {
            // Empty or invalid email field!
            showEmailError(activity.getString(R.string.error_emailinput_invalid), 1);
            return false;
        }

        if (DataHelper.isEmailAlreadyPresent(mainActivity, email)) {
            // We add each email only once
            showEmailError(activity.getString(R.string.error_emailinput_duplicate), 2);
            return false;
        }

        if (DataHelper.insertContact(mainActivity, name, email, organization, title)) {
            mainActivity.showCroutonNao(activity.getString(R.string.new_contact_added, email), Style.CONFIRM);
            mainActivity.updateParticipantsCount();

            return true;
        }

        return false;
    } else {
        Log.e(TAG, "The parent Activity is not MainActivity! Wat is this I don't even");
        if (DEBUG)
            Log.d(TAG, "Activity class: " + activity.getLocalClassName());
        Toast.makeText(activity, activity.getString(R.string.insert_failed_wrong_parent), Toast.LENGTH_SHORT)
                .show();
        return true; // We can close, there's nothing to do anyway
    }
}