Java Code Examples for android.content.Context#getClass()
The following examples show how to use
android.content.Context#getClass() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java From soundcom with Apache License 2.0 | 6 votes |
public void clickHelper(Context context,EditText mEdit, View v) { src = mEdit.getText().toString(); while (src.length() != 30) { src += " "; } mEdit.setText(src); System.out.println(context.getClass()); if(context.getClass()==android.app.Application.class) {generate(context); fab_trans.show();} else return; }
Example 2
Source File: MainActivity.java From soundcom with Apache License 2.0 | 6 votes |
public void write(String JSONcontent,Message message,Context context,File myInternalFile){ if(isFilePresent(context, "storage.json")) { try { FileOutputStream fOut = new FileOutputStream(myInternalFile); fOut.write(JSONcontent.getBytes()); fOut.close(); System.out.println("Done"); } catch (IOException e) { e.printStackTrace(); } //proceed with storing the first todo or show ui } else { create(context, "storage.json", "{}"); if(context.getClass()==android.app.Application.class) printmessage(message); } }
Example 3
Source File: PluginInstrumentation.java From DroidPlugin with GNU Lesser General Public License v3.0 | 6 votes |
private void fixBaseContextImplContentResolverOpsPackage(Context context) throws IllegalAccessException { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1 && context != null && !TextUtils.equals(context.getPackageName(), mHostContext.getPackageName())) { Context baseContext = context; Class clazz = baseContext.getClass(); Field mContentResolver = FieldUtils.getDeclaredField(clazz, "mContentResolver", true); if (mContentResolver != null) { Object valueObj = mContentResolver.get(baseContext); if (valueObj instanceof ContentResolver) { ContentResolver contentResolver = ((ContentResolver) valueObj); Field mPackageName = FieldUtils.getDeclaredField(ContentResolver.class, "mPackageName", true); Object mPackageNameValueObj = mPackageName.get(contentResolver); if (mPackageNameValueObj != null && mPackageNameValueObj instanceof String) { String packageName = ((String) mPackageNameValueObj); if (!TextUtils.equals(packageName, mHostContext.getPackageName())) { mPackageName.set(contentResolver, mHostContext.getPackageName()); Log.i(TAG, "fixBaseContextImplContentResolverOpsPackage OK!Context=%s,contentResolver=%s", baseContext, contentResolver); } } } } } }
Example 4
Source File: PluginInstrumentation.java From DroidPlugin with GNU Lesser General Public License v3.0 | 6 votes |
private void fixBaseContextImplOpsPackage(Context context) throws IllegalAccessException { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1 && context != null && !TextUtils.equals(context.getPackageName(), mHostContext.getPackageName())) { Context baseContext = context; Class clazz = baseContext.getClass(); Field mOpPackageName = FieldUtils.getDeclaredField(clazz, "mOpPackageName", true); if (mOpPackageName != null) { Object valueObj = mOpPackageName.get(baseContext); if (valueObj instanceof String) { String opPackageName = ((String) valueObj); if (!TextUtils.equals(opPackageName, mHostContext.getPackageName())) { mOpPackageName.set(baseContext, mHostContext.getPackageName()); Log.i(TAG, "fixBaseContextImplOpsPackage OK!Context=%s,", baseContext); } } } } }
Example 5
Source File: SpoonScreenshotAction.java From android-material-stepper with Apache License 2.0 | 5 votes |
/** * Get the activity from the context of the view * * @param view View from which the activity will be inferred * @return Activity that contains the given view */ private static Activity getActivity(final View view) { Context context = view.getContext(); while (!(context instanceof Activity)) { if (context instanceof ContextWrapper) { context = ((ContextWrapper) context).getBaseContext(); } else { throw new IllegalStateException("Got a context of class " + context.getClass() + " and I don't know " + "how to get the Activity from it"); } } return (Activity) context; }
Example 6
Source File: SettingsActivity.java From android-grid-wichterle with Apache License 2.0 | 5 votes |
private String getVersionName(Context ctx) { try { ComponentName comp = new ComponentName(ctx, ctx.getClass()); PackageInfo pinfo = ctx.getPackageManager().getPackageInfo(comp.getPackageName(), 0); return pinfo.versionName; } catch (android.content.pm.PackageManager.NameNotFoundException e) { return "unknown"; } }
Example 7
Source File: MenuInflater.java From android-apps with MIT License | 5 votes |
public InflatedOnMenuItemClickListener(Context context, String methodName) { mContext = context; Class<?> c = context.getClass(); try { mMethod = c.getMethod(methodName, PARAM_TYPES); } catch (Exception e) { InflateException ex = new InflateException( "Couldn't resolve menu item onClick handler " + methodName + " in class " + c.getName()); ex.initCause(e); throw ex; } }
Example 8
Source File: TransferringFragment.java From AndroidPlayground with MIT License | 5 votes |
@Override public void onAttach(Context context) { super.onAttach(context); if (context instanceof ScreenTransferController) { mScreenTransferController = (ScreenTransferController) context; } else { throw new IllegalStateException( context.getClass() + "Activity must implement ScreenTransferController"); } }
Example 9
Source File: CountdownFragment4Viewers.java From AndroidPlayground with MIT License | 5 votes |
@Override public void onAttach(Context context) { super.onAttach(context); if (context instanceof ScreenTransferController) { mScreenTransferController = (ScreenTransferController) context; } else { throw new IllegalStateException( context.getClass() + "Activity must implement ScreenTransferController"); } }
Example 10
Source File: BaseNoteFragment.java From nextcloud-notes with GNU General Public License v3.0 | 5 votes |
@Override public void onAttach(@NonNull Context context) { super.onAttach(context); try { listener = (NoteFragmentListener) context; } catch (ClassCastException e) { throw new ClassCastException(context.getClass() + " must implement " + NoteFragmentListener.class); } db = NotesDatabase.getInstance(context); }
Example 11
Source File: SpoonScreenshotAction.java From espresso-cucumber with Apache License 2.0 | 5 votes |
/** * Get the activity from the context of the view * @param view View from which the activity will be inferred * @return Activity that contains the given view */ private static Activity getActivity(final View view) { Context context = view.getContext(); while (!(context instanceof Activity)) { if (context instanceof ContextWrapper) { context = ((ContextWrapper) context).getBaseContext(); } else { throw new IllegalStateException("Got a context of class " + context.getClass() + " and I don't know how to get the Activity from it"); } } return (Activity) context; }
Example 12
Source File: UpdateFunGO.java From UpdateFun with Apache License 2.0 | 5 votes |
private static Notification.Builder notificationInit(Context context) { Intent intent = new Intent(context, context.getClass()); PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent, 0); Notification.Builder builder = new Notification.Builder(context); builder.setSmallIcon(android.R.drawable.stat_sys_download) .setTicker("开始下载") .setContentTitle(GetAppInfo.getAppName(context)) .setContentText("正在更新") .setContentIntent(pIntent) .setWhen(System.currentTimeMillis()); return builder; }
Example 13
Source File: BeautyLog.java From AndroidAnimationExercise with Apache License 2.0 | 5 votes |
public static void printClickInfo(View view) { Context context = view.getContext(); Class contextClass = context.getClass(); String humanId = context.getResources().getResourceName(view.getId()); String packageName = context.getResources().getResourcePackageName(view.getId()); Log.e(0 + TRACK, TOP_BORDER); Log.e(1 + TRACK, String.format(CLASS_FORMAT, HORIZONTAL_LINE, contextClass.getCanonicalName())); Log.e(2 + TRACK, String.format(VIEW_NAME_FORMAT, HORIZONTAL_LINE, humanId)); Log.e(3 + TRACK, String.format(PACK_NAME_FORMAT, HORIZONTAL_LINE, packageName)); Log.e(4 + TRACK, BOTTOM_BORDER); }
Example 14
Source File: StatusServiceImpl.java From Status with Apache License 2.0 | 5 votes |
public static Class getCompatClass(Context context) { if (context instanceof StatusService || context instanceof StatusServiceCompat) return context.getClass(); //prevents issues disabling services during compatibility switch return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && !((Boolean) PreferenceData.STATUS_NOTIFICATIONS_COMPAT.getValue(context)) ? StatusService.class : StatusServiceCompat.class; }
Example 15
Source File: AppTool.java From FastAndroid with Apache License 2.0 | 5 votes |
/** * 下载APK * * @param context * @param apkUrl */ public static void downLoadApk(@NonNull Context context, @IdRes int appIcon, @NonNull String appName, @NonNull String channelId, @NonNull String apkUrl) { NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder builder = new NotificationCompat.Builder(context,channelId); Intent intent = new Intent(context, context.getClass()); intent.putExtra("isRetry", false); //未完成 }
Example 16
Source File: ErrorDialog.java From justaline-android with Apache License 2.0 | 5 votes |
@Override public void onAttach(Context context) { super.onAttach(context); try { mListener = (Listener) context; } catch (ClassCastException e) { throw new ClassCastException(context.getClass() + " must implement Listener"); } }
Example 17
Source File: ClearDrawingDialog.java From justaline-android with Apache License 2.0 | 5 votes |
@Override public void onAttach(Context context) { super.onAttach(context); try { mListener = (Listener) context; } catch (ClassCastException e) { throw new ClassCastException(context.getClass() + " must implement Listener"); } }
Example 18
Source File: LeaveRoomDialog.java From justaline-android with Apache License 2.0 | 5 votes |
@Override public void onAttach(Context context) { super.onAttach(context); try { mListener = (Listener) context; } catch (ClassCastException e) { throw new ClassCastException(context.getClass() + " must implement Listener"); } }
Example 19
Source File: NotificationWrapper.java From react-native-jw-media-player with MIT License | 4 votes |
public Notification createNotification(Context context, MediaSessionCompat mediaSession, long capabilities ) { int appIcon = context.getResources().getIdentifier("ic_app_icon", "drawable", context.getPackageName()); // Media metadata MediaControllerCompat controller = mediaSession.getController(); MediaMetadataCompat mediaMetadata = controller.getMetadata(); MediaDescriptionCompat description = mediaMetadata.getDescription(); // Notification NotificationCompat.Builder builder = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID); builder.setContentTitle(description.getTitle()) .setContentText(description.getSubtitle()) .setSubText(description.getDescription()) .setLargeIcon(description.getIconBitmap()) .setOnlyAlertOnce(true) .setStyle(new MediaStyle() .setMediaSession(mediaSession.getSessionToken()) .setShowActionsInCompactView(0)) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setSmallIcon(appIcon > 0 ? appIcon : R.drawable.ic_jw_developer) .setDeleteIntent(getActionIntent(context, KeyEvent.KEYCODE_MEDIA_STOP)); // Attach actions to the notification. if ((capabilities & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0) { builder.addAction(R.drawable.ic_previous, "Previous", getActionIntent(context, KeyEvent.KEYCODE_MEDIA_PREVIOUS)); } if ((capabilities & PlaybackStateCompat.ACTION_PAUSE) != 0) { builder.addAction(R.drawable.ic_pause, "Pause", getActionIntent(context, KeyEvent.KEYCODE_MEDIA_PAUSE)); } if ((capabilities & PlaybackStateCompat.ACTION_PLAY) != 0) { builder.addAction(R.drawable.ic_play, "Play", getActionIntent(context, KeyEvent.KEYCODE_MEDIA_PLAY) ); } if ((capabilities & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0) { builder.addAction(R.drawable.ic_next, "Next", getActionIntent(context, KeyEvent.KEYCODE_MEDIA_NEXT)); } // We want to resume the existing VideoActivity, over creating a new one. Intent intent = new Intent(context, context.getClass()); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); builder.setContentIntent(pendingIntent); Notification notification = builder.build(); mNotificationManager.notify(NOTIFICATION_ID, notification); return notification; }
Example 20
Source File: StandOutWindowManager.java From FloatUtil with MIT License | 4 votes |
private StandOutWindowManager(Context context) { this.mContext = context; this.mServClass = context.getClass(); this.mSysWindowManager = (android.view.WindowManager) context.getSystemService(Context.WINDOW_SERVICE); }