Example usage for android.content Context getClass

List of usage examples for android.content Context getClass

Introduction

In this page you can find the example usage for android.content Context getClass.

Prototype

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

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:za.co.neilson.alarm.alert.AlarmAlertActivity.java

public static int sendNotification(Context context, String str, Alarm alarm) {

    Toast.makeText(context, str, Toast.LENGTH_SHORT).show();

    int mId = 1;//  ww w  .  ja  v a2  s  .c o  m

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle(context.getString(R.string.app_name))
            .setContentText(str);
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, context.getClass());
    resultIntent.putExtra("alarm", alarm);
    // The stack builder object will contain an artificial back stack for the
    // started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(context.getClass());
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(mId, mBuilder.build());
    return mId;
}

From source file:org.sipdroid.sipua.ui.Receiver.java

public static synchronized SipdroidEngine engine(Context context) {
    if (mContext == null || !context.getClass().getName().contains("ReceiverRestrictedContext"))
        mContext = context;//  w  w w.  ja  v  a  2s  .  c  o  m
    if (mSipdroidEngine == null) {
        if (android.os.Build.VERSION.SDK_INT > 9) {
            ReceiverNew.setPolicy();
        }
        mSipdroidEngine = new SipdroidEngine();
        mSipdroidEngine.StartEngine();
        if (Integer.parseInt(Build.VERSION.SDK) >= 8)
            Bluetooth.init();
    } else
        mSipdroidEngine.CheckEngine();
    context.startService(new Intent(context, RegisterService.class));
    return mSipdroidEngine;
}

From source file:com.eyekabob.util.EyekabobHelper.java

public static Dialog createAboutDialog(Context context) {
    final Dialog dialog = new Dialog(context);
    dialog.setContentView(R.layout.about_dialog);
    dialog.setTitle(R.string.about_eyekabob_caps);

    ImageView imageView = (ImageView) dialog.findViewById(R.id.aboutDialogImage);
    imageView.setImageResource(R.drawable.ic_launcher);

    String message = context.getResources().getString(R.string.eyekabob_version);
    String versionName = "";
    try {/*ww  w  .  j a  v  a  2  s .c  o  m*/
        versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(context.getClass().getSimpleName(), e.getMessage());
    }

    message += versionName;
    message += "\n\n" + context.getResources().getString(R.string.about_eyekabob_app);
    message += "\n\n" + context.getResources().getString(R.string.about_last_fm);

    TextView textView = (TextView) dialog.findViewById(R.id.aboutDialogText);
    textView.setText(message);

    dialog.findViewById(R.id.aboutDialogButton).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dialog.dismiss();
        }
    });

    return dialog;
}

From source file:de.dev.eth0.rssreader.app.util.ActivityStarterHelper.java

/**
 * displays the given feed/*from  w w  w.  j a  v  a2 s  .c o  m*/
 *
 * @param id
 * @param context
 */
public static void displayFeedEntry(Context context, Long id) {
    if (context instanceof FragmentActivity) {
        FragmentActivity activity = (FragmentActivity) context;
        // Depending on the design, we either update the FeedEntryFragment or start a new activity
        FeedEntryFragment feedEntryFragment = (FeedEntryFragment) activity.getSupportFragmentManager()
                .findFragmentById(R.id.feed_detail);
        if (feedEntryFragment != null && feedEntryFragment.isAdded()) {
            Timber.d("Updating feedEntryFragment %d", id);
            feedEntryFragment.displayFeedEntry(id);
        } else {
            Timber.d("Starting FeedEntryDetailActivity for Feed %d", id);
            activity.startActivity(
                    new Intent(context, FeedEntryDetailActivity.class).putExtra(FeedEntryTable.COLUMN_ID, id));
        }
    } else {
        Timber.e("Could not display feed entry as the context has the wrong class %s", context.getClass());
    }
}

From source file:com.facebook.internal.Utility.java

/**
 * Returns the name of the current activity if the context is an activity, otherwise return "unknown"
 */// w  w  w. j a  v  a 2  s.  co  m
public static String getActivityName(Context context) {
    if (context == null) {
        return "null";
    } else if (context == context.getApplicationContext()) {
        return "unknown";
    } else {
        return context.getClass().getSimpleName();
    }
}

From source file:io.github.runassudo.ptoffline.utils.TransportrUtils.java

static public void startGeoIntent(Context context, Location loc) {
    String lat = Double.toString(loc.lat / 1E6);
    String lon = Double.toString(loc.lon / 1E6);

    String uri1 = "geo:0,0?q=" + lat + "," + lon;
    String uri2;//from   ww  w  . j  a  va 2s.c  o m

    try {
        uri2 = "(" + URLEncoder.encode(TransportrUtils.getLocName(loc), "utf-8") + ")";
    } catch (UnsupportedEncodingException e) {
        uri2 = "(" + TransportrUtils.getLocName(loc) + ")";
    }

    Uri geo = Uri.parse(uri1 + uri2);

    Log.d(context.getClass().getCanonicalName(), "Starting geo intent: " + geo.toString());

    // show station on external map
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(geo);
    if (intent.resolveActivity(context.getPackageManager()) != null) {
        context.startActivity(intent);
    }
}

From source file:de.grobox.liberario.utils.TransportrUtils.java

static public void startGeoIntent(Context context, Location loc) {
    String lat = Double.toString(loc.lat / 1E6);
    String lon = Double.toString(loc.lon / 1E6);

    String uri1 = "geo:0,0?q=" + lat + "," + lon;
    String uri2;/* ww  w .  j  a  v a  2 s.c  o m*/

    try {
        uri2 = "(" + URLEncoder.encode(TransportrUtils.getLocationName(loc), "utf-8") + ")";
    } catch (UnsupportedEncodingException e) {
        uri2 = "(" + TransportrUtils.getLocationName(loc) + ")";
    }

    Uri geo = Uri.parse(uri1 + uri2);

    Log.d(context.getClass().getCanonicalName(), "Starting geo intent: " + geo.toString());

    // show station on external map
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(geo);
    if (intent.resolveActivity(context.getPackageManager()) != null) {
        context.startActivity(intent);
    }
}

From source file:com.miandui.utils.runtimePermission.AndPermission.java

/**
 * Parse the request results./* w  ww. ja va  2s .  co  m*/
 *
 * @param o            {@link Activity} or {@link android.support.v4.app.Fragment} or
 *                     {@link android.app.Fragment}.
 * @param requestCode  request code.
 * @param permissions  all permissions.
 * @param grantResults results.
 */
private static void callbackAnnotation(@NonNull Context o, int requestCode, @NonNull String[] permissions,
        int[] grantResults) {
    List<String> grantedList = new ArrayList<>();
    List<String> deniedList = new ArrayList<>();
    for (int i = 0; i < permissions.length; i++) {
        //            if (grantResults[i] == PackageManager.PERMISSION_GRANTED)
        //                grantedList.add(permissions[i]);
        //MIUI
        if (CheckPermission.isGranted(o, permissions[i]))
            grantedList.add(permissions[i]);
        else
            deniedList.add(permissions[i]);
    }

    boolean isAllGrant = deniedList.isEmpty();

    Class<? extends Annotation> clazz = isAllGrant ? PermissionYes.class : PermissionNo.class;
    Method[] methods = findMethodForRequestCode(o.getClass(), clazz, requestCode);
    if (methods.length == 0) {
        Log.e(TAG, "Not found the callback method, do you forget @PermissionYes or @permissionNo"
                + " for callback method ? Or you can use PermissionListener.");
    } else
        try {
            for (Method method : methods) {
                if (!method.isAccessible())
                    method.setAccessible(true);
                method.invoke(o, isAllGrant ? grantedList : deniedList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
}

From source file:ru.tlrs.vincent.VincentView.java

private FragmentManager getContextFragmentManager(Context context) {
    FragmentManager result = null;//from w  ww .j  av  a2  s  .c o m
    try {
        Method method = context.getClass().getMethod("getSupportFragmentManager");
        try {
            result = (FragmentManager) method.invoke(context);
        } catch (IllegalAccessException e) {
            Log.d(LOG_TAG, "getContextFragmentManager: IllegalAccessException");
        } catch (InvocationTargetException e) {
            Log.d(LOG_TAG, "getContextFragmentManager: InvocationTargetException");
        }
    } catch (NoSuchMethodException e) {
        Log.d(LOG_TAG,
                "showLightBox: Method getSupportFragmentManager() is not exist. Parent view class mast be derive from Compat classes.");
    }
    return result;
}

From source file:com.andremion.louvre.home.GalleryFragment.java

@Override
public void onAttach(Context context) {
    super.onAttach(context);
    if (!(context instanceof Callbacks)) {
        throw new IllegalArgumentException(
                context.getClass().getSimpleName() + " must implement " + Callbacks.class.getName());
    }/*from ww  w  . j  a va2 s  .c  om*/
    mCallbacks = (Callbacks) context;
    if (!(context instanceof FragmentActivity)) {
        throw new IllegalArgumentException(
                context.getClass().getSimpleName() + " must inherit from " + FragmentActivity.class.getName());
    }
    mMediaLoader.onAttach((FragmentActivity) context, this);
}