Search in sources :

Example 71 with TargetApi

use of android.annotation.TargetApi in project react-native-navigation by wix.

the class ReactDevPermission method askPermission.

@TargetApi(23)
public static void askPermission(Context context) {
    if (shouldAskPermission()) {
        Intent serviceIntent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
        context.startActivity(serviceIntent);
        String msg = "Overlay permissions needs to be granted in order for react native apps to run in dev mode";
        Log.w(ReactConstants.TAG, "======================================\n\n");
        Log.w(ReactConstants.TAG, msg);
        Log.w(ReactConstants.TAG, "\n\n======================================");
        for (int i = 0; i < 5; i++) {
            Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
        }
    }
}
Also used : Intent(android.content.Intent) TargetApi(android.annotation.TargetApi)

Example 72 with TargetApi

use of android.annotation.TargetApi in project WordPress-Android by wordpress-mobile.

the class NotificationsUtils method isNotificationsEnabled.

// Checks if global notifications toggle is enabled in the Android app settings
// See: https://code.google.com/p/android/issues/detail?id=38482#c15
@SuppressWarnings("unchecked")
@TargetApi(19)
public static boolean isNotificationsEnabled(Context context) {
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        AppOpsManager mAppOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        ApplicationInfo appInfo = context.getApplicationInfo();
        String pkg = context.getApplicationContext().getPackageName();
        int uid = appInfo.uid;
        Class appOpsClass;
        try {
            appOpsClass = Class.forName(AppOpsManager.class.getName());
            Method checkOpNoThrowMethod = appOpsClass.getMethod(CHECK_OP_NO_THROW, Integer.TYPE, Integer.TYPE, String.class);
            Field opPostNotificationValue = appOpsClass.getDeclaredField(OP_POST_NOTIFICATION);
            int value = (int) opPostNotificationValue.get(Integer.class);
            return ((int) checkOpNoThrowMethod.invoke(mAppOps, value, uid, pkg) == AppOpsManager.MODE_ALLOWED);
        } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            AppLog.e(T.NOTIFS, e.getMessage());
        }
    }
    // Default to assuming notifications are enabled
    return true;
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) Field(java.lang.reflect.Field) AppOpsManager(android.app.AppOpsManager) TargetApi(android.annotation.TargetApi)

Example 73 with TargetApi

use of android.annotation.TargetApi in project PreviewSeekBar by rubensousa.

the class PreviewAnimatorLollipopImpl method startUnreveal.

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void startUnreveal() {
    Animator animator = ViewAnimationUtils.createCircularReveal(previewView, getCenterX(previewView), getCenterY(previewView), getRadius(previewView), morphView.getWidth() * 2);
    animator.setTarget(previewView);
    animator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            previewView.animate().setListener(null);
            frameView.setVisibility(View.INVISIBLE);
            previewView.setVisibility(View.INVISIBLE);
            morphView.setVisibility(View.VISIBLE);
            morphView.animate().y(getHideY()).scaleY(0.5f).scaleX(0.5f).setDuration(UNMORPH_MOVE_DURATION).setInterpolator(new AccelerateInterpolator()).setListener(hideListener);
        }
    });
    frameView.animate().alpha(1f).setDuration(UNMORPH_UNREVEAL_DURATION).setInterpolator(new AccelerateInterpolator());
    animator.setDuration(UNMORPH_UNREVEAL_DURATION).setInterpolator(new AccelerateInterpolator());
    animator.start();
}
Also used : Animator(android.animation.Animator) AccelerateInterpolator(android.view.animation.AccelerateInterpolator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) TargetApi(android.annotation.TargetApi)

Example 74 with TargetApi

use of android.annotation.TargetApi in project sugar by satyan.

the class CursorTests method testMakeAdapter.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testMakeAdapter() {
    save(new SimpleModel());
    Cursor c = Select.from(SimpleModel.class).getCursor();
    CursorAdapter adapter = new CursorAdapter(RuntimeEnvironment.application, c, true) {

        @Override
        public View newView(Context context, Cursor cursor, ViewGroup parent) {
            TextView tv = new TextView(context);
            String s = cursor.getString(cursor.getColumnIndex("STR"));
            tv.setText(s);
            return null;
        }

        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            String s = cursor.getString(cursor.getColumnIndex("STR"));
            ((TextView) view).setText(s);
        }
    };
    Assert.assertNotNull(adapter);
}
Also used : SimpleModel(com.orm.model.SimpleModel) Context(android.content.Context) CursorAdapter(android.widget.CursorAdapter) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) Cursor(android.database.Cursor) TextView(android.widget.TextView) View(android.view.View) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 75 with TargetApi

use of android.annotation.TargetApi in project muzei by romannurik.

the class GallerySettingsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gallery_activity);
    Toolbar appBar = (Toolbar) findViewById(R.id.app_bar);
    setSupportActionBar(appBar);
    getSupportLoaderManager().initLoader(0, null, this);
    bindService(new Intent(this, GalleryArtSource.class).setAction(GalleryArtSource.ACTION_BIND_GALLERY), mServiceConnection, BIND_AUTO_CREATE);
    mPlaceholderDrawable = new ColorDrawable(ContextCompat.getColor(this, R.color.gallery_chosen_photo_placeholder));
    mPlaceholderSmallDrawable = new ColorDrawable(ContextCompat.getColor(this, R.color.gallery_chosen_photo_placeholder));
    mPhotoGridView = (RecyclerView) findViewById(R.id.photo_grid);
    DefaultItemAnimator itemAnimator = new DefaultItemAnimator();
    itemAnimator.setSupportsChangeAnimations(false);
    mPhotoGridView.setItemAnimator(itemAnimator);
    setupMultiSelect();
    final GridLayoutManager gridLayoutManager = new GridLayoutManager(GallerySettingsActivity.this, 1);
    mPhotoGridView.setLayoutManager(gridLayoutManager);
    final ViewTreeObserver vto = mPhotoGridView.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            int width = mPhotoGridView.getWidth() - mPhotoGridView.getPaddingStart() - mPhotoGridView.getPaddingEnd();
            if (width <= 0) {
                return;
            }
            // Compute number of columns
            int maxItemWidth = getResources().getDimensionPixelSize(R.dimen.gallery_chosen_photo_grid_max_item_size);
            int numColumns = 1;
            while (true) {
                if (width / numColumns > maxItemWidth) {
                    ++numColumns;
                } else {
                    break;
                }
            }
            int spacing = getResources().getDimensionPixelSize(R.dimen.gallery_chosen_photo_grid_spacing);
            mItemSize = (width - spacing * (numColumns - 1)) / numColumns;
            // Complete setup
            gridLayoutManager.setSpanCount(numColumns);
            mChosenPhotosAdapter.setHasStableIds(true);
            mPhotoGridView.setAdapter(mChosenPhotosAdapter);
            mPhotoGridView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            tryUpdateSelection(false);
        }
    });
    ViewCompat.setOnApplyWindowInsetsListener(mPhotoGridView, new OnApplyWindowInsetsListener() {

        @Override
        public WindowInsetsCompat onApplyWindowInsets(final View v, final WindowInsetsCompat insets) {
            int gridSpacing = getResources().getDimensionPixelSize(R.dimen.gallery_chosen_photo_grid_spacing);
            ViewCompat.onApplyWindowInsets(v, insets.replaceSystemWindowInsets(insets.getSystemWindowInsetLeft() + gridSpacing, gridSpacing, insets.getSystemWindowInsetRight() + gridSpacing, insets.getSystemWindowInsetBottom() + insets.getSystemWindowInsetTop() + gridSpacing + getResources().getDimensionPixelSize(R.dimen.gallery_fab_space)));
            return insets;
        }
    });
    Button enableRandomImages = (Button) findViewById(R.id.gallery_enable_random);
    enableRandomImages.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View view) {
            ActivityCompat.requestPermissions(GallerySettingsActivity.this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, REQUEST_STORAGE_PERMISSION);
        }
    });
    Button permissionSettings = (Button) findViewById(R.id.gallery_edit_permission_settings);
    permissionSettings.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View view) {
            Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", getPackageName(), null));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
    });
    mAddButton = findViewById(R.id.add_fab);
    mAddButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                // On Lollipop and higher, we show the add toolbar to allow users to add either
                // individual photos or a whole directory
                showAddToolbar();
            } else {
                requestPhotos();
            }
        }
    });
    mAddToolbar = findViewById(R.id.add_toolbar);
    findViewById(R.id.add_photos).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View v) {
            requestPhotos();
        }
    });
    findViewById(R.id.add_folder).setOnClickListener(new View.OnClickListener() {

        @TargetApi(Build.VERSION_CODES.LOLLIPOP)
        @Override
        public void onClick(final View v) {
            Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
            try {
                startActivityForResult(intent, REQUEST_CHOOSE_FOLDER);
                SharedPreferences preferences = getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
                if (preferences.getBoolean(SHOW_INTERNAL_STORAGE_MESSAGE, true)) {
                    Toast.makeText(GallerySettingsActivity.this, R.string.gallery_internal_storage_message, Toast.LENGTH_LONG).show();
                }
            } catch (ActivityNotFoundException e) {
                Snackbar.make(mPhotoGridView, R.string.gallery_add_folder_error, Snackbar.LENGTH_LONG).show();
                hideAddToolbar(true);
            }
        }
    });
}
Also used : SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) WindowInsetsCompat(android.support.v4.view.WindowInsetsCompat) OnApplyWindowInsetsListener(android.support.v4.view.OnApplyWindowInsetsListener) ColorDrawable(android.graphics.drawable.ColorDrawable) GridLayoutManager(android.support.v7.widget.GridLayoutManager) Button(android.widget.Button) ActivityNotFoundException(android.content.ActivityNotFoundException) ViewTreeObserver(android.view.ViewTreeObserver) TargetApi(android.annotation.TargetApi) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

TargetApi (android.annotation.TargetApi)1365 Intent (android.content.Intent)153 View (android.view.View)147 Test (org.junit.Test)119 SuppressLint (android.annotation.SuppressLint)115 Uri (android.net.Uri)70 ArrayList (java.util.ArrayList)68 Animator (android.animation.Animator)67 Point (android.graphics.Point)64 Window (android.view.Window)56 TextView (android.widget.TextView)56 IOException (java.io.IOException)56 ViewGroup (android.view.ViewGroup)53 Matchers.anyString (org.mockito.Matchers.anyString)53 SharedPreferences (android.content.SharedPreferences)44 File (java.io.File)44 Field (java.lang.reflect.Field)44 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)43 Bitmap (android.graphics.Bitmap)42 ImageView (android.widget.ImageView)40