Example usage for android.app Activity getClass

List of usage examples for android.app Activity getClass

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.amazon.android.navigator.Navigator.java

/**
 * {@inheritDoc}//w  ww  .  ja  v a2  s.c o  m
 */
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {

    String activityName = getActivityName(activity);
    Log.d(TAG, activityName + " onActivityCreated");

    String screenName = mScreenNameMap.get(activity.getClass().getName());
    mCurrentActivity = activity;
    if (mINavigationListener != null) {
        mINavigationListener.onScreenCreate(activity, screenName);
        mINavigationListener.onSetTheme(activity);
    }
}

From source file:de.persoapp.android.core.adapter.MainViewFragment.java

protected void excludeFromRecentAppList(Activity activity) {
    // a dirty hack to exclude this activity from the recent app list after the process finished
    // since it runs in singleInstance mode onNewIntent will be called
    final Intent intent = new Intent(activity, activity.getClass());
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    startActivity(intent);/* w ww  .ja v a2  s  .  c om*/
}

From source file:com.ovrhere.android.morseflash.ui.fragments.MainFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    try {//from w w  w .j ava2 s .c  o m
        mFragmentInteractionListener = (OnFragmentInteractionListener) activity;
    } catch (ClassCastException e) {
        String message = "Activity \"" + activity.getClass().getSimpleName()
                + "\" must implement OnFragmentInteractionListener";
        Log.e(CLASS_NAME, message);
        throw new ClassCastException(message);
    }
}

From source file:com.actionbarsherlock.internal.widget.ActionBarView.java

/**
 * Attempt to programmatically load the logo from the manifest file of an
 * activity by using an XML pull parser. This should allow us to read the
 * logo attribute regardless of the platform it is being run on.
 *
 * @param activity Activity instance.//www.j av  a2  s . c  o m
 * @return Logo resource ID.
 */
private static int loadLogoFromManifest(Activity activity) {
    int logo = 0;
    try {
        final String thisPackage = activity.getClass().getName();
        if (DEBUG)
            Log.i(TAG, "Parsing AndroidManifest.xml for " + thisPackage);

        final String packageName = activity.getApplicationInfo().packageName;
        final AssetManager am = activity.createPackageContext(packageName, 0).getAssets();
        final XmlResourceParser xml = am.openXmlResourceParser("AndroidManifest.xml");

        int eventType = xml.getEventType();
        while (eventType != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_TAG) {
                String name = xml.getName();

                if ("application".equals(name)) {
                    //Check if the <application> has the attribute
                    if (DEBUG)
                        Log.d(TAG, "Got <application>");

                    for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
                        if (DEBUG)
                            Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i));

                        if ("logo".equals(xml.getAttributeName(i))) {
                            logo = xml.getAttributeResourceValue(i, 0);
                            break; //out of for loop
                        }
                    }
                } else if ("activity".equals(name)) {
                    //Check if the <activity> is us and has the attribute
                    if (DEBUG)
                        Log.d(TAG, "Got <activity>");
                    Integer activityLogo = null;
                    String activityPackage = null;
                    boolean isOurActivity = false;

                    for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
                        if (DEBUG)
                            Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i));

                        //We need both uiOptions and name attributes
                        String attrName = xml.getAttributeName(i);
                        if ("logo".equals(attrName)) {
                            activityLogo = xml.getAttributeResourceValue(i, 0);
                        } else if ("name".equals(attrName)) {
                            activityPackage = ActionBarSherlockCompat.cleanActivityName(packageName,
                                    xml.getAttributeValue(i));
                            if (!thisPackage.equals(activityPackage)) {
                                break; //on to the next
                            }
                            isOurActivity = true;
                        }

                        //Make sure we have both attributes before processing
                        if ((activityLogo != null) && (activityPackage != null)) {
                            //Our activity, logo specified, override with our value
                            logo = activityLogo.intValue();
                        }
                    }
                    if (isOurActivity) {
                        //If we matched our activity but it had no logo don't
                        //do any more processing of the manifest
                        break;
                    }
                }
            }
            eventType = xml.nextToken();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (DEBUG)
        Log.i(TAG, "Returning " + Integer.toHexString(logo));
    return logo;
}

From source file:fr.cobaltians.cobalt.activities.CobaltActivity.java

public void popTo(String controller, String page) {
    Intent popToIntent = Cobalt.getInstance(this).getIntentForController(controller, page);

    if (popToIntent != null) {
        Bundle popToExtras = popToIntent.getBundleExtra(Cobalt.kExtras);
        String popToActivityClassName = popToExtras.getString(Cobalt.kActivity);

        try {/*from  w  w w. jav a2 s.c o  m*/
            Class<?> popToActivityClass = Class.forName(popToActivityClassName);

            boolean popToControllerFound = false;
            int popToControllerIndex = -1;

            for (int i = sActivitiesArrayList.size() - 1; i >= 0; i--) {
                Activity oldActivity = sActivitiesArrayList.get(i);
                Class<?> oldActivityClass = oldActivity.getClass();

                Bundle oldBundle = oldActivity.getIntent().getExtras();
                Bundle oldExtras = (oldBundle != null) ? oldBundle.getBundle(Cobalt.kExtras) : null;
                String oldPage = (oldExtras != null) ? oldExtras.getString(Cobalt.kPage) : null;

                if (oldPage == null && CobaltActivity.class.isAssignableFrom(oldActivityClass)) {
                    Fragment fragment = ((CobaltActivity) oldActivity).getSupportFragmentManager()
                            .findFragmentById(((CobaltActivity) oldActivity).getFragmentContainerId());
                    if (fragment != null) {
                        oldExtras = fragment.getArguments();
                        oldPage = (oldExtras != null) ? oldExtras.getString(Cobalt.kPage) : null;
                    }
                }

                if (popToActivityClass.equals(oldActivityClass) && (!CobaltActivity.class
                        .isAssignableFrom(oldActivityClass)
                        || (CobaltActivity.class.isAssignableFrom(oldActivityClass) && page.equals(oldPage)))) {
                    popToControllerFound = true;
                    popToControllerIndex = i;
                    break;
                }
            }

            if (popToControllerFound) {
                while (popToControllerIndex + 1 <= sActivitiesArrayList.size()) {
                    sActivitiesArrayList.get(popToControllerIndex + 1).finish();
                }
            } else if (Cobalt.DEBUG)
                Log.w(Cobalt.TAG, TAG + " - popTo: controller " + controller
                        + (page == null ? "" : " with page " + page) + " not found in history. Abort.");
        } catch (ClassNotFoundException exception) {
            exception.printStackTrace();
        }
    } else if (Cobalt.DEBUG)
        Log.e(Cobalt.TAG, TAG + " - popTo: unable to pop to null controller");
}

From source file:com.fbartnitzek.tasteemall.filter.EntityFilterDialogFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);

    // communication with the MainActivity to return filter uri

    // http://stackoverflow.com/questions/10905312/receive-result-from-dialogfragment
    if (activity instanceof GenericFilterFinishListener) {
        finishListener = (GenericFilterFinishListener) activity;
    } else {//from  www . j  av  a 2  s  .  c  o m
        throw new ClassCastException(activity.getClass().getSimpleName() + " must implement "
                + GenericFilterFinishListener.class.getSimpleName());
    }

}

From source file:es.usc.citius.servando.calendula.fragments.MedicineCreateOrEditFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);

    Log.d(getTag(),//from w w w . ja v a2s . c  o m
            "Activity " + activity.getClass().getName() + ", " + (activity instanceof OnMedicineEditListener));
    // If the container activity has implemented
    // the callback interface, set it as listener
    if (activity instanceof OnMedicineEditListener) {
        mMedicineEditCallback = (OnMedicineEditListener) activity;
    }
    if (activity instanceof ScheduleCreationActivity) {
        this.showConfirmButton = false;
    }
}

From source file:dev.nick.accessories.injection.processors.PermissionProcessor.java

@Override
public boolean process(@NonNull Object obj, @NonNull Type type) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
        return false;

    in();//from  w w  w .  j a va 2 s.c  o  m

    Activity activity = null;

    if (obj instanceof Activity) {
        activity = (Activity) obj;
    }

    if (obj instanceof Fragment) {
        Fragment fragment = (Fragment) obj;
        activity = fragment.getActivity();
    }

    if (obj instanceof android.support.v4.app.Fragment) {
        android.support.v4.app.Fragment fragment = (android.support.v4.app.Fragment) obj;
        activity = fragment.getActivity();
    }

    Preconditions.checkNotNull(activity, "Only Activity or Fragment is supported for this annotation.");

    RequestPermissions autoRequirePermission = activity.getClass().getAnnotation(RequestPermissions.class);
    int code = autoRequirePermission.requestCode();

    String[] scope = autoRequirePermission.permissions();
    String[] required;
    if (scope.length == 0) {
        scope = getPkgInfo(activity).requestedPermissions;
        required = extractUnGranted(activity, scope);
    } else {
        required = extractUnGranted(activity, scope);
    }
    if (required == null || required.length == 0) {
        int[] codes = new int[0];
        if (required != null) {
            codes = new int[scope.length];
            for (int i = 0; i < codes.length; i++) {
                codes[i] = PackageManager.PERMISSION_GRANTED;
            }
        }
        activity.onRequestPermissionsResult(code, scope, codes);
    } else {
        activity.requestPermissions(required, code);
    }
    return true;
}

From source file:com.nick.scalpel.core.request.RequestPermissionWirer.java

@Override
public void wire(Object obj) {

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
        return;/*from  w w  w .  ja va 2  s.c  om*/

    Activity activity = null;

    if (obj instanceof Activity) {
        activity = (Activity) obj;
    }

    if (obj instanceof Fragment) {
        Fragment fragment = (Fragment) obj;
        activity = fragment.getActivity();
    }

    if (obj instanceof android.support.v4.app.Fragment) {
        android.support.v4.app.Fragment fragment = (android.support.v4.app.Fragment) obj;
        activity = fragment.getActivity();
    }

    Preconditions.checkNotNull(activity, "Only Activity or Fragment(app/v4) is supported for this annotation.");

    RequirePermission autoRequirePermission = activity.getClass().getAnnotation(RequirePermission.class);
    int code = autoRequirePermission.requestCode();

    String[] scope = autoRequirePermission.permissions();
    String[] required;
    if (scope.length == 0) {
        scope = getPkgInfo(activity).requestedPermissions;
        required = extractUnGranted(activity, scope);
    } else {
        required = extractUnGranted(activity, scope);
    }
    if (required == null || required.length == 0) {
        int[] codes = new int[0];
        if (required != null) {
            codes = new int[scope.length];
            for (int i = 0; i < codes.length; i++) {
                codes[i] = PackageManager.PERMISSION_GRANTED;
            }
        }
        activity.onRequestPermissionsResult(code, scope, codes);
    } else {
        activity.requestPermissions(required, code);
    }
}

From source file:fr.mixit.android.ui.fragments.SessionDetailsFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);

    if (!(activity instanceof SessionDetailsContract)) {
        throw new IllegalArgumentException(
                activity.getClass().getName() + " must implement SessionDetailsContract");
    }/*from w  ww  . j a va2  s  .c  o  m*/
}