/*
 * Copyright (c) 2017 大前良介 (OHMAE Ryosuke)
 *
 * This software is released under the MIT License.
 * http://opensource.org/licenses/MIT
 */

package net.mm2d.android.util;

import android.annotation.TargetApi;
import android.app.Activity;
import android.graphics.Point;
import android.os.Build;
import android.support.annotation.NonNull;
import android.view.Display;

import java.lang.reflect.InvocationTargetException;

/**
 * ディスプレイサイズを取得するユーティリティクラス。
 *
 * @author <a href="mailto:ryo@mm2d.net">大前良介 (OHMAE Ryosuke)</a>
 */
public class DisplaySizeUtils {
    private DisplaySizeUtils() {
        throw new AssertionError();
    }

    /**
     * SystemUIを除いたディスプレイサイズを返す。
     *
     * @param activity Activity
     * @return ディスプレイサイズ
     * @see Display#getSize(Point)
     */
    @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
    @NonNull
    public static Point getSize(@NonNull final Activity activity) {
        final Display display = activity.getWindowManager().getDefaultDisplay();
        final Point point = new Point();
        display.getSize(point);
        return point;
    }

    /**
     * SystemUIを含むディスプレイサイズを返す。
     *
     * @param activity Activity
     * @return ディスプレイサイズ
     * @see Display#getRealSize(Point)
     */
    @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
    @NonNull
    public static Point getRealSize(@NonNull final Activity activity) {
        final Display display = activity.getWindowManager().getDefaultDisplay();
        final Point point = new Point();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            display.getRealSize(point);
            return point;
        }
        try {
            final int width = (Integer) Display.class.getMethod("getRawWidth").invoke(display);
            final int height = (Integer) Display.class.getMethod("getRawHeight").invoke(display);
            point.set(width, height);
        } catch (final IllegalAccessException ignored) {
        } catch (final InvocationTargetException ignored) {
        } catch (final NoSuchMethodException ignored) {
        }
        return point;
    }

    /**
     * アプリケーションエリア内のNavigationBarエリアを返す。
     *
     * @param activity Activity
     * @return NavigationBarのエリア
     */
    @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
    @NonNull
    public static Point getNavigationBarArea(@NonNull final Activity activity) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT // KitKat未満はアプリエリアと重複しない
                || isInMultiWindowMode(activity)) {
            return new Point(0, 0);
        }
        final Point p1 = getSize(activity);
        final Point p2 = getRealSize(activity);
        return new Point(p2.x - p1.x, p2.y - p1.y);
    }

    private static boolean isInMultiWindowMode(@NonNull final Activity activity) {
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && activity.isInMultiWindowMode();
    }
}

@@ -173,45 +173,8 @@
 l;%0A%0A
-import android.annotation.TargetApi;%0A
 impo
@@ -198,16 +198,16 @@
 tivity;%0A
+
 import a
@@ -746,58 +746,8 @@
  */%0A
-    @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)%0A
     
@@ -1161,58 +1161,8 @@
  */%0A
-    @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)%0A
     
@@ -2094,24 +2094,24 @@
 Bar%E3%81%AE%E3%82%A8%E3%83%AA%E3%82%A2%0A
+
      */%0A
     @Tar
@@ -2106,58 +2106,8 @@
  */%0A
-    @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)%0A
     

delete unnecessary anotation.