Example usage for android.os Trace beginSection

List of usage examples for android.os Trace beginSection

Introduction

In this page you can find the example usage for android.os Trace beginSection.

Prototype

public static void beginSection(String sectionName) 

Source Link

Document

Writes a trace message to indicate that a given section of code has begun.

Usage

From source file:Main.java

/**
 * Returns true if 20% of the image's top right corner is white, or 20% of the bottom
 * of the image is white./*  w ww.ja va  2 s  .  c o m*/
 */
public static boolean isBitmapWhiteAtTopOrBottom(Bitmap largeBitmap) {
    if (Build.VERSION.SDK_INT >= 18) {
        Trace.beginSection("isBitmapWhiteAtTopOrBottom");
    }
    try {
        final Bitmap smallBitmap = scaleBitmapDown(largeBitmap);

        final int[] rgbPixels = new int[smallBitmap.getWidth() * smallBitmap.getHeight()];
        smallBitmap.getPixels(rgbPixels, 0, smallBitmap.getWidth(), 0, 0, smallBitmap.getWidth(),
                smallBitmap.getHeight());

        // look at top right corner of the bitmap
        int whiteCount = 0;
        for (int y = 0; y < smallBitmap.getHeight() * HEIGHT_PERCENT_ANALYZED; y++) {
            for (int x = (int) (smallBitmap.getWidth() * (1 - THIRD)); x < smallBitmap.getWidth(); x++) {
                final int rgb = rgbPixels[y * smallBitmap.getWidth() + x];
                if (isWhite(rgb)) {
                    whiteCount++;
                }
            }
        }
        int totalPixels = (int) (smallBitmap.getHeight() * smallBitmap.getWidth() * THIRD
                * HEIGHT_PERCENT_ANALYZED);
        if (whiteCount / (float) totalPixels > PROPORTION_WHITE_CUTOFF) {
            return true;
        }

        // look at bottom portion of bitmap
        whiteCount = 0;
        for (int y = (int) (smallBitmap.getHeight() * (1 - HEIGHT_PERCENT_ANALYZED)); y < smallBitmap
                .getHeight(); y++) {
            for (int x = 0; x < smallBitmap.getWidth(); x++) {
                final int rgb = rgbPixels[y * smallBitmap.getWidth() + x];
                if (isWhite(rgb)) {
                    whiteCount++;
                }
            }
        }

        totalPixels = (int) (smallBitmap.getHeight() * smallBitmap.getWidth() * HEIGHT_PERCENT_ANALYZED);

        return whiteCount / (float) totalPixels > PROPORTION_WHITE_CUTOFF;
    } finally {
        if (Build.VERSION.SDK_INT >= 18) {
            Trace.endSection();
        }
    }
}

From source file:Main.java

/**
 * Returns true if 20% of the image's top right corner is white, or 20% of the bottom
 * of the image is white./*from ww w. jav  a  2 s.co m*/
 */
public static boolean isBitmapWhiteAtTopOrBottom(@NonNull Bitmap largeBitmap) {
    if (Build.VERSION.SDK_INT >= 18) {
        Trace.beginSection("isBitmapWhiteAtTopOrBottom");
    }
    try {
        final Bitmap smallBitmap = scaleBitmapDown(largeBitmap);

        final int[] rgbPixels = new int[smallBitmap.getWidth() * smallBitmap.getHeight()];
        smallBitmap.getPixels(rgbPixels, 0, smallBitmap.getWidth(), 0, 0, smallBitmap.getWidth(),
                smallBitmap.getHeight());

        // look at top right corner of the bitmap
        int whiteCount = 0;
        for (int y = 0; y < smallBitmap.getHeight() * HEIGHT_PERCENT_ANALYZED; y++) {
            for (int x = (int) (smallBitmap.getWidth() * (1 - THIRD)); x < smallBitmap.getWidth(); x++) {
                final int rgb = rgbPixels[y * smallBitmap.getWidth() + x];
                if (isWhite(rgb)) {
                    whiteCount++;
                }
            }
        }
        int totalPixels = (int) (smallBitmap.getHeight() * smallBitmap.getWidth() * THIRD
                * HEIGHT_PERCENT_ANALYZED);
        if (whiteCount / (float) totalPixels > PROPORTION_WHITE_CUTOFF) {
            return true;
        }

        // look at bottom portion of bitmap
        whiteCount = 0;
        for (int y = (int) (smallBitmap.getHeight() * (1 - HEIGHT_PERCENT_ANALYZED)); y < smallBitmap
                .getHeight(); y++) {
            for (int x = 0; x < smallBitmap.getWidth(); x++) {
                final int rgb = rgbPixels[y * smallBitmap.getWidth() + x];
                if (isWhite(rgb)) {
                    whiteCount++;
                }
            }
        }

        totalPixels = (int) (smallBitmap.getHeight() * smallBitmap.getWidth() * HEIGHT_PERCENT_ANALYZED);

        return whiteCount / (float) totalPixels > PROPORTION_WHITE_CUTOFF;
    } finally {
        if (Build.VERSION.SDK_INT >= 18) {
            Trace.endSection();
        }
    }
}

From source file:Main.java

/**
 * Returns true if 20% of the image's top right corner is white, or 20% of the bottom
 * of the image is white.//w  ww  . ja v  a2 s .c om
 */
public static boolean isBitmapWhiteAtTopOrBottom(Bitmap largeBitmap) {
    Trace.beginSection("isBitmapWhiteAtTopOrBottom");
    try {
        final Bitmap smallBitmap = scaleBitmapDown(largeBitmap);

        final int[] rgbPixels = new int[smallBitmap.getWidth() * smallBitmap.getHeight()];
        smallBitmap.getPixels(rgbPixels, 0, smallBitmap.getWidth(), 0, 0, smallBitmap.getWidth(),
                smallBitmap.getHeight());

        // look at top right corner of the bitmap
        int whiteCount = 0;
        for (int y = 0; y < smallBitmap.getHeight() * HEIGHT_PERCENT_ANALYZED; y++) {
            for (int x = (int) (smallBitmap.getWidth() * (1 - THIRD)); x < smallBitmap.getWidth(); x++) {
                final int rgb = rgbPixels[y * smallBitmap.getWidth() + x];
                if (isWhite(rgb)) {
                    whiteCount++;
                }
            }
        }
        int totalPixels = (int) (smallBitmap.getHeight() * smallBitmap.getWidth() * THIRD
                * HEIGHT_PERCENT_ANALYZED);
        if (whiteCount / (float) totalPixels > PROPORTION_WHITE_CUTOFF) {
            return true;
        }

        // look at bottom portion of bitmap
        whiteCount = 0;
        for (int y = (int) (smallBitmap.getHeight() * (1 - HEIGHT_PERCENT_ANALYZED)); y < smallBitmap
                .getHeight(); y++) {
            for (int x = 0; x < smallBitmap.getWidth(); x++) {
                final int rgb = rgbPixels[y * smallBitmap.getWidth() + x];
                if (isWhite(rgb)) {
                    whiteCount++;
                }
            }
        }

        totalPixels = (int) (smallBitmap.getHeight() * smallBitmap.getWidth() * HEIGHT_PERCENT_ANALYZED);

        return whiteCount / (float) totalPixels > PROPORTION_WHITE_CUTOFF;
    } finally {
        Trace.endSection();
    }
}

From source file:com.android.contacts.util.MaterialColorMapUtils.java

/**
 * Return primary and secondary colors from the Material color palette that are similar to
 * {@param color}./* ww  w  .j a  v a  2 s.c om*/
 */
public MaterialPalette calculatePrimaryAndSecondaryColor(int color) {
    Trace.beginSection("calculatePrimaryAndSecondaryColor");

    final float colorHue = hue(color);
    float minimumDistance = Float.MAX_VALUE;
    int indexBestMatch = 0;
    for (int i = 0; i < sPrimaryColors.length(); i++) {
        final int primaryColor = sPrimaryColors.getColor(i, 0);
        final float comparedHue = hue(primaryColor);
        // No need to be perceptually accurate when calculating color distances since
        // we are only mapping to 15 colors. Being slightly inaccurate isn't going to change
        // the mapping very often.
        final float distance = Math.abs(comparedHue - colorHue);
        if (distance < minimumDistance) {
            minimumDistance = distance;
            indexBestMatch = i;
        }
    }

    Trace.endSection();
    return new MaterialPalette(sPrimaryColors.getColor(indexBestMatch, 0),
            sSecondaryColors.getColor(indexBestMatch, 0));
}

From source file:com.android.contacts.common.activity.RequestPermissionsActivityBase.java

private void requestPermissions() {
    Trace.beginSection("requestPermissions");
    try {//from   www .  j a  va 2 s .c o  m
        // Construct a list of missing permissions
        final ArrayList<String> unsatisfiedPermissions = new ArrayList<>();
        for (String permission : getDesiredPermissions()) {
            if (checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
                unsatisfiedPermissions.add(permission);
            }
        }
        if (unsatisfiedPermissions.size() == 0) {
            throw new RuntimeException(
                    "Request permission activity was called even" + " though all permissions are satisfied.");
        }
        ActivityCompat.requestPermissions(this,
                unsatisfiedPermissions.toArray(new String[unsatisfiedPermissions.size()]),
                PERMISSIONS_REQUEST_ALL_PERMISSIONS);
    } finally {
        Trace.endSection();
    }
}

From source file:com.android.contacts.common.activity.RequestPermissionsActivityBase.java

protected static boolean hasPermissions(Context context, String[] permissions) {
    Trace.beginSection("hasPermission");
    try {//from w  w  w .j a  va 2  s.  c om
        for (String permission : permissions) {
            if (ContextCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
                return false;
            }
        }
        return true;
    } finally {
        Trace.endSection();
    }
}

From source file:com.android.contacts.activities.RequestPermissionsActivityBase.java

protected static boolean hasPermissions(Context context, String[] permissions) {
    Trace.beginSection("hasPermission");
    try {//from ww w. j a  v a 2s .  com
        for (String permission : permissions) {
            if (!PermissionsUtil.hasPermission(context, permission)) {
                return false;
            }
        }
        return true;
    } finally {
        Trace.endSection();
    }
}

From source file:com.android.contacts.activities.RequestPermissionsActivityBase.java

private void requestPermissions() {
    Trace.beginSection("requestPermissions");
    try {/*ww w .  j  av  a2s. c om*/
        // Construct a list of missing permissions
        final ArrayList<String> unsatisfiedPermissions = new ArrayList<>();
        for (String permission : getPermissions()) {
            if (!PermissionsUtil.hasPermission(this, permission)) {
                unsatisfiedPermissions.add(permission);
            }
        }
        if (unsatisfiedPermissions.size() == 0) {
            throw new RuntimeException(
                    "Request permission activity was called even" + " though all permissions are satisfied.");
        }
        ActivityCompat.requestPermissions(this,
                unsatisfiedPermissions.toArray(new String[unsatisfiedPermissions.size()]),
                PERMISSIONS_REQUEST_ALL_PERMISSIONS);
    } finally {
        Trace.endSection();
    }
}

From source file:com.android.dialer.list.ListsFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    Trace.beginSection(TAG + " onCreate");
    super.onCreate(savedInstanceState);

    mVoicemailStatusHelper = new VoicemailStatusHelperImpl();
    mHasFetchedVoicemailStatus = false;/*from ww w  .j  av a  2s  .  c  o m*/

    mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    mHasActiveVoicemailProvider = mPrefs
            .getBoolean(VisualVoicemailEnabledChecker.PREF_KEY_HAS_ACTIVE_VOICEMAIL_PROVIDER, false);

    Trace.endSection();
}

From source file:com.android.dialer.list.ListsFragment.java

@Override
public void onResume() {
    Trace.beginSection(TAG + " onResume");
    super.onResume();

    mActionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
    if (getUserVisibleHint()) {
        sendScreenViewForCurrentPosition();
    }/*from w  w  w.j  av  a  2  s.  c o m*/

    // Fetch voicemail status to determine if we should show the voicemail tab.
    mCallLogQueryHandler = new CallLogQueryHandler(getActivity(), getActivity().getContentResolver(), this);
    mCallLogQueryHandler.fetchVoicemailStatus();
    mCallLogQueryHandler.fetchMissedCallsUnreadCount();
    Trace.endSection();
}