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.commonsware.android.eu4youtb.ContractListFragment.java

@SuppressWarnings("unchecked")
@Override//from w  ww . j  av a  2 s . c o  m
public void onAttach(Activity activity) {
    super.onAttach(activity);

    try {
        contract = (T) activity;
    } catch (ClassCastException e) {
        throw new IllegalStateException(activity.getClass().getSimpleName()
                + " does not implement contract interface for " + getClass().getSimpleName(), e);
    }
}

From source file:com.google.android.apps.gutenberg.AccountSelectionDialogFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    if (!(activity instanceof OnAccountSelectedListener)) {
        throw new RuntimeException(activity.getClass().getSimpleName() + " needs to implement "
                + OnAccountSelectedListener.class.getSimpleName());
    }/*from www . j a v a 2s  .c  o  m*/
    mListener = (OnAccountSelectedListener) activity;
}

From source file:com.dalaran.annotation.FieldMerge.java

private void clickAnnotation(Click annotation, Field field, final Activity a) {
    try {//from   w  w w .  ja v  a2s . c om
        String method = annotation.value();
        final Method declaredMethod = a.getClass().getDeclaredMethod(method);
        View o = (View) field.get(a);
        o.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    declaredMethod.setAccessible(true);
                    declaredMethod.invoke(a);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    } catch (Throwable e) {
        e.printStackTrace();
    }
}

From source file:zack.yovel.clear.controller.foreground.SuggestionsDialogFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    try {/* w w w. j a v  a2  s .  c  o  m*/
        listener = (OnSelectionMade) activity;
    } catch (ClassCastException e) {
        Log.e(TAG, activity.getClass().getName() + " must implement " + OnSelectionMade.class.getName());
    }
}

From source file:com.clanofthecloud.cotcpushnotifications.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.// w w  w  .  j a  va  2s  .  com
 */
private void sendNotification(String message) {
    Activity currentAct = UnityPlayer.currentActivity;
    Class activityToOpen = currentAct != null ? currentAct.getClass() : UnityPlayerActivity.class;
    Intent intent = new Intent(this, activityToOpen);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    ApplicationInfo ai = null;
    try {
        ai = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
        int notificationIcon = ai.metaData.getInt("cotc.GcmNotificationIcon", -1);
        if (notificationIcon == -1) {
            Log.e(TAG,
                    "!!!!!!!!! cotc.GcmNotificationIcon not configured in manifest, push notifications won't work !!!!!!!!!");
            return;
        }
        int notificationLargeIcon = ai.metaData.getInt("cotc.GcmNotificationLargeIcon", -1);
        if (notificationLargeIcon == -1) {
            Log.e(TAG, "There is no large icon for push notifs, will only use default icon");
            return;
        }

        String pushNotifName = ai.metaData.getString("cotc.GcmNotificationTitle");
        if (pushNotifName == null) {
            Log.e(TAG,
                    "!!!!!!!!! cotc.GcmNotificationTitle not configured in manifest, push notifications won't work !!!!!!!!!");
            return;
        }

        if (notifManager == null)
            notifManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationCompat.Builder notificationBuilder;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            int importance = NotificationManager.IMPORTANCE_HIGH;
            NotificationChannel channel = new NotificationChannel("CotC Channel", "CotC Channel", importance);
            channel.setDescription("CotC Channel");
            notifManager.createNotificationChannel(channel);
            notificationBuilder = new NotificationCompat.Builder(this, "CotC Channel");
        } else
            notificationBuilder = new NotificationCompat.Builder(this);

        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        notificationBuilder.setSmallIcon(notificationIcon).setContentTitle(pushNotifName)
                .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
                .setContentIntent(pendingIntent).setPriority(Notification.PRIORITY_HIGH);
        if (notificationLargeIcon != -1)
            notificationBuilder.setLargeIcon(
                    BitmapFactory.decodeResource(currentAct.getResources(), notificationLargeIcon));

        notifManager.notify(0 /* ID of notification */, notificationBuilder.build());
    } catch (Exception e) {
        Log.w(TAG, "Failed to handle push notification", e);
    }
}

From source file:com.morlunk.mumbleclient.wizard.WizardCertificateFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    try {// ww  w .  ja v a2 s  .  co  m
        mNavigation = (WizardNavigation) activity;
    } catch (ClassCastException e) {
        throw new RuntimeException(activity.getClass().getName() + " must implement WizardNavigation!");
    }
}

From source file:com.silentcircle.contacts.interactions.GroupCreationDialogFragment.java

@Override
protected void onCompleted(String groupLabel) {

    // Indicate to the listener that a new group will be created.
    // If the device is rotated, mListener will become null, so that the
    // popup from GroupMembershipView will not be shown.
    if (mListener != null) {
        mListener.onGroupCreated();//from w  w w . j  av a  2  s  .c  o m
    }

    Activity activity = getActivity();
    activity.startService(ScContactSaveService.createNewGroupIntent(activity, groupLabel,
            null /* no new members to add */, activity.getClass(), Intent.ACTION_EDIT));
}

From source file:com.secupwn.aimsicd.AndroidIMSICatcherDetector.java

public void detach(Activity activity) {
    if (activity == null) {
        return;//w  ww  . jav a2s . c o m
    }

    log.debug("BaseTask detach:" + activity.getClass().getCanonicalName());

    List<BaseAsyncTask<?, ?, ?>> tasks = mActivityTaskMap
            .get(activity.getClass().getCanonicalName().hashCode());
    if (tasks != null) {
        for (BaseAsyncTask<?, ?, ?> task : tasks) {
            task.setActivity(null);
        }
    }
}

From source file:shared.dialog.fixedorderdialog.BaseDialogFragment.java

@SuppressWarnings("unchecked")
@Override/*  ww  w.j a  v  a  2 s. c o m*/
public void onAttach(Activity activity) {
    super.onAttach(activity);

    try {
        listener = (Listener) activity;
    } catch (ClassCastException e) {
        if (!isListenerOptional())
            throw new ClassCastException(activity.getClass().getName() + " must implement listener interface.");
    }
}

From source file:org.schabi.newpipe.settings.SelectChannelFragment.java

protected boolean onError(Throwable e) {
    final Activity activity = getActivity();
    ErrorActivity.reportError(activity, e, activity.getClass(), null,
            ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR, "none", "", R.string.app_ui_crash));
    return true;//www.j  a va  2s .c o m
}