Search in sources :

Example 31 with TargetApi

use of android.annotation.TargetApi in project plaid by nickbutcher.

the class ShortcutHelper method disablePostShortcut.

@TargetApi(Build.VERSION_CODES.N_MR1)
public static void disablePostShortcut(@NonNull Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1)
        return;
    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
    shortcutManager.disableShortcuts(DYNAMIC_SHORTCUT_IDS);
}
Also used : ShortcutManager(android.content.pm.ShortcutManager) TargetApi(android.annotation.TargetApi)

Example 32 with TargetApi

use of android.annotation.TargetApi in project android by owncloud.

the class DisplayUtils method convertIdn.

/**
     * Converts an internationalized domain name (IDN) in an URL to and from ASCII/Unicode.
     * @param url the URL where the domain name should be converted
     * @param toASCII if true converts from Unicode to ASCII, if false converts from ASCII to Unicode
     * @return the URL containing the converted domain name
     */
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
public static String convertIdn(String url, boolean toASCII) {
    String urlNoDots = url;
    String dots = "";
    while (urlNoDots.startsWith(".")) {
        urlNoDots = url.substring(1);
        dots = dots + ".";
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        // Find host name after '//' or '@'
        int hostStart = 0;
        if (urlNoDots.indexOf("//") != -1) {
            hostStart = url.indexOf("//") + "//".length();
        } else if (url.indexOf("@") != -1) {
            hostStart = url.indexOf("@") + "@".length();
        }
        int hostEnd = url.substring(hostStart).indexOf("/");
        // Handle URL which doesn't have a path (path is implicitly '/')
        hostEnd = (hostEnd == -1 ? urlNoDots.length() : hostStart + hostEnd);
        String host = urlNoDots.substring(hostStart, hostEnd);
        host = (toASCII ? IDN.toASCII(host) : IDN.toUnicode(host));
        return dots + urlNoDots.substring(0, hostStart) + host + urlNoDots.substring(hostEnd);
    } else {
        return dots + url;
    }
}
Also used : Point(android.graphics.Point) TargetApi(android.annotation.TargetApi)

Example 33 with TargetApi

use of android.annotation.TargetApi in project android by owncloud.

the class UriUtils method getLocalPath.

/**
     * Translates a content:// URI referred to a local file file to a path on the local filesystem
     *
     * @param uri       The URI to resolve
     * @return          The path in the file system to the content or null if it could not be found (not a file)
     */
@TargetApi(Build.VERSION_CODES.KITKAT)
public static String getLocalPath(Uri uri, Context context) {
    final boolean isKitKatOrLater = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
    // DocumentProvider
    if (isKitKatOrLater && DocumentsContract.isDocumentUri(context, uri)) {
        // ExternalStorageProvider
        if (UriUtils.isExternalStorageDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];
            if ("primary".equalsIgnoreCase(type)) {
                return Environment.getExternalStorageDirectory() + "/" + split[1];
            }
        } else // DownloadsProvider
        if (UriUtils.isDownloadsDocument(uri)) {
            final String id = DocumentsContract.getDocumentId(uri);
            final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
            return UriUtils.getDataColumn(context, contentUri, null, null);
        } else // MediaProvider
        if (UriUtils.isMediaDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];
            Uri contentUri = null;
            if ("image".equals(type)) {
                contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
            } else if ("video".equals(type)) {
                contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
            } else if ("audio".equals(type)) {
                contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
            }
            final String selection = "_id=?";
            final String[] selectionArgs = new String[] { split[1] };
            return UriUtils.getDataColumn(context, contentUri, selection, selectionArgs);
        } else // Documents providers returned as content://...
        if (UriUtils.isContentDocument(uri)) {
            return uri.toString();
        }
    } else // MediaStore (and general)
    if ("content".equalsIgnoreCase(uri.getScheme())) {
        // Return the remote address
        if (UriUtils.isGooglePhotosUri(uri))
            return uri.getLastPathSegment();
        return UriUtils.getDataColumn(context, uri, null, null);
    } else // File
    if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }
    return null;
}
Also used : Uri(android.net.Uri) TargetApi(android.annotation.TargetApi)

Example 34 with TargetApi

use of android.annotation.TargetApi in project superCleanMaster by joyoyao.

the class RubbishCleanActivity method setTranslucentStatus.

@TargetApi(19)
private void setTranslucentStatus(boolean on) {
    Window win = getWindow();
    WindowManager.LayoutParams winParams = win.getAttributes();
    final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
    if (on) {
        winParams.flags |= bits;
    } else {
        winParams.flags &= ~bits;
    }
    win.setAttributes(winParams);
}
Also used : Window(android.view.Window) WindowManager(android.view.WindowManager) TargetApi(android.annotation.TargetApi)

Example 35 with TargetApi

use of android.annotation.TargetApi in project Synthese_2BIN by TheYoungSensei.

the class LoginActivity method showProgress.

/**
     * Shows the progress UI and hides the login form.
     */
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
private void showProgress(final boolean show) {
    // the progress spinner.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);
        mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
        mLoginFormView.animate().setDuration(shortAnimTime).alpha(show ? 0 : 1).setListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
            }
        });
        mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
        mProgressView.animate().setDuration(shortAnimTime).alpha(show ? 1 : 0).setListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
            }
        });
    } else {
        // The ViewPropertyAnimator APIs are not available, so simply show
        // and hide the relevant UI components.
        mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
        mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
    }
}
Also used : Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) TargetApi(android.annotation.TargetApi)

Aggregations

TargetApi (android.annotation.TargetApi)1367 Intent (android.content.Intent)153 View (android.view.View)148 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)54 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)43 ImageView (android.widget.ImageView)40