Java Code Examples for android.content.res.Configuration#SCREENLAYOUT_SIZE_SMALL

The following examples show how to use android.content.res.Configuration#SCREENLAYOUT_SIZE_SMALL . 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: MediaItemLayout.java    From boxing with Apache License 2.0 6 votes vote down vote up
private ScreenType getScreenType(Context context) {
    int type = context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
    ScreenType result;
    switch (type) {
        case Configuration.SCREENLAYOUT_SIZE_SMALL:
            result = ScreenType.SMALL;
            break;
        case Configuration.SCREENLAYOUT_SIZE_NORMAL:
            result = ScreenType.NORMAL;
            break;
        case Configuration.SCREENLAYOUT_SIZE_LARGE:
            result = ScreenType.LARGE;
            break;
        default:
            result = ScreenType.NORMAL;
            break;
    }
    return result;
}
 
Example 2
Source File: StartupActions.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * detect and  initialize text size
 */
public static void textSizeDetection(SharedPreferences sharedPreferences) {
    userTextSize = sharedPreferences.getInt(SHP_SETTING.KEY_MESSAGE_TEXT_SIZE, 14);

    if (!G.context.getResources().getBoolean(R.bool.isTablet)) {

        int screenLayout = context.getResources().getConfiguration().screenLayout;
        screenLayout &= Configuration.SCREENLAYOUT_SIZE_MASK;

        switch (screenLayout) {
            case Configuration.SCREENLAYOUT_SIZE_SMALL:
                userTextSize = (userTextSize * 3) / 4;
                break;
            case Configuration.SCREENLAYOUT_SIZE_NORMAL:
                break;
            case Configuration.SCREENLAYOUT_SIZE_LARGE:
                userTextSize = (userTextSize * 3) / 2;
                break;
            case Configuration.SCREENLAYOUT_SIZE_XLARGE:// or 4
                userTextSize *= 2;
        }
    }
}
 
Example 3
Source File: UI.java    From android-lockpattern with Apache License 2.0 6 votes vote down vote up
/**
 * Gets current screen size.
 * 
 * @param context
 *            the context.
 * @return current screen size.
 */
public static ScreenSize getCurrent(Context context) {
    switch (context.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) {
    case Configuration.SCREENLAYOUT_SIZE_SMALL:
        return SMALL;
    case Configuration.SCREENLAYOUT_SIZE_NORMAL:
        return NORMAL;
    case Configuration.SCREENLAYOUT_SIZE_LARGE:
        return LARGE;
    case Configuration.SCREENLAYOUT_SIZE_XLARGE:
        return XLARGE;
    default:
        return UNDEFINED;
    }
}
 
Example 4
Source File: UI.java    From android-lockpattern with Apache License 2.0 6 votes vote down vote up
/**
 * Gets current screen size.
 * 
 * @param context
 *            the context.
 * @return current screen size.
 */
public static ScreenSize getCurrent(Context context) {
    switch (context.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) {
    case Configuration.SCREENLAYOUT_SIZE_SMALL:
        return SMALL;
    case Configuration.SCREENLAYOUT_SIZE_NORMAL:
        return NORMAL;
    case Configuration.SCREENLAYOUT_SIZE_LARGE:
        return LARGE;
    case Configuration.SCREENLAYOUT_SIZE_XLARGE:
        return XLARGE;
    default:
        return UNDEFINED;
    }
}
 
Example 5
Source File: ProjectBaseActivity.java    From sms-ticket with Apache License 2.0 6 votes vote down vote up
private void printDebugInfo() {
    DisplayMetrics displaymetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    DebugLog.i("Device density: " + displaymetrics.densityDpi);
    if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
        DebugLog.i("Device size is: LARGE");
    }
    if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
        DebugLog.i("Device size is: XLARGE");
    }
    if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) {
        DebugLog.i("Device size is: NORMAL");
    }
    if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) {
        DebugLog.i("Device size is: SMALL");
    }
    DebugLog.i("Device is tablet: " + UIUtils.isHoneycombTablet(this));
}
 
Example 6
Source File: UIUtils.java    From sms-ticket with Apache License 2.0 6 votes vote down vote up
public static String getScreenSizeAsString(Context context) {
    String size = null;
    int screenLayout = context.getResources().getConfiguration().screenLayout;
    if ((screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
        size = "large";
    }
    if ((screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
        size = "xlarge";
    }
    if ((screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) {
        size = "normal";
    }
    if ((screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) {
        size = "small";
    }
    if ((screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
        size = "undefined";
    }
    return size;
}
 
Example 7
Source File: DynamicLayoutUtils.java    From dynamic-support with Apache License 2.0 5 votes vote down vote up
/**
 * Get the column count according to the current configuration.
 * <p>It will also consider multi-window mode on API 24 and above devices.
 *
 * <p>It is not recommended to do this calculation at runtime. So, please define all the
 * span counts in xml.
 *
 * @param context The context to get configuration.
 * @param defaultCount The default column count.
 * @param maxCount The maximum column count up to which we can scale.
 * @param compact {@code true} if the layout is compact and disable the auto increase of
 *                columns in multi-window mode.
 *
 * @return The column count according to the current device configurations.
 */
@TargetApi(Build.VERSION_CODES.N)
public static int getLayoutColumns(@NonNull Context context,
        int defaultCount, int maxCount, boolean compact) {
    int columns = defaultCount;
    int screenCategory = getScreenSizeCategory(context);

    switch (screenCategory) {
        case Configuration.SCREENLAYOUT_SIZE_SMALL:
            if (columns > 1) {
                columns = columns - 1;
            }
            break;
        case Configuration.SCREENLAYOUT_SIZE_NORMAL:
            break;
        case Configuration.SCREENLAYOUT_SIZE_LARGE:
            if (context.getResources().getConfiguration().orientation
                    != Configuration.ORIENTATION_LANDSCAPE) {
                break;
            }
        case Configuration.SCREENLAYOUT_SIZE_XLARGE:
            columns += 1;
            break;
    }

    if (context.getResources().getConfiguration().orientation
            == Configuration.ORIENTATION_LANDSCAPE){
        try {
            if (compact || !isInMultiWindowMode(context)) {
                columns *= 2;
            }
        } catch (Exception ignored) {
        }
    }

    return Math.min(columns, maxCount);
}
 
Example 8
Source File: StartActivity.java    From jpHolo with MIT License 5 votes vote down vote up
private String checkScreenSize() {
	String screenSize;
	if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
		screenSize = "xlarge";
	} else if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
		screenSize = "large";
	} else if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) {
		screenSize = "normal";
	} else if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) {
		screenSize = "small";
	} else {
		screenSize = "normal";
	}
	return screenSize;
}
 
Example 9
Source File: StartActivityUri.java    From jpHolo with MIT License 5 votes vote down vote up
private String checkScreenSize() {
	String screenSize = "normal";
	if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
		screenSize = "xlarge";
	} else if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
		screenSize = "large";
	} else if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) {
		screenSize = "normal";
	} else if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) {
		screenSize = "small";
	} else {
		screenSize = "normal";
	}
	return screenSize;
}
 
Example 10
Source File: PreferredScreenSize.java    From jpHolo with MIT License 5 votes vote down vote up
private String checkScreenSize() {
	String screenSize = "normal";
	if ((cordova.getActivity().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
		screenSize = "xlarge";
	} else if ((cordova.getActivity().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
		screenSize = "large";
	} else if ((cordova.getActivity().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) {
		screenSize = "normal";
	} else if ((cordova.getActivity().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) {
		screenSize = "small";
	} else {
		screenSize = "normal";
	}
	return screenSize;
}
 
Example 11
Source File: ScreenUtils.java    From OffsetAnimator with MIT License 4 votes vote down vote up
/**
 * @param context Context instance
 * @return [true] if the device has a small screen, [false] otherwise.
 */
public static boolean hasSmallScreen(Context context) {
    if (context == null) return false;
    return getScreenSize(context) == Configuration.SCREENLAYOUT_SIZE_SMALL;
}
 
Example 12
Source File: SlidingTabLayout.java    From iGap-Android with GNU Affero General Public License v3.0 4 votes vote down vote up
protected TextView createDefaultTabView(Context context, int i) {

        TextView textView = new TextView(context);
        textView.setGravity(Gravity.CENTER);

        if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP * 2);
        } else if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float) (TAB_VIEW_TEXT_SIZE_SP * 1.5));
        } else if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) {
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
        } else if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) {
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float) (TAB_VIEW_TEXT_SIZE_SP * .75));
        } else {
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
        }

        //    textView.setTypeface(custom_font);
        textView.setTextColor(Color.WHITE);
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH) {// allcaps is for api 14 and upper
            textView.setAllCaps(false);
        }

        if (i == 0) {
            textView.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 8.5f));
        } else if (i == 1) {
            textView.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 8.5f));
        } else if (i == 2) {
            textView.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 8.5f));
        } else {
            textView.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 8.5f));
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            TypedValue outValue = new TypedValue();
            getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
            textView.setBackgroundResource(outValue.resourceId);
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style

        }

        float dp = getResources().getDisplayMetrics().density;
        textView.setPadding(2, (int) (20 * dp), 2, (int) (20 * dp));

        return textView;
    }
 
Example 13
Source File: ViewUtils.java    From TheGreatAdapter with Apache License 2.0 4 votes vote down vote up
public static boolean isSmallScreen(Context context) {
    return getScreenSize(context) == Configuration.SCREENLAYOUT_SIZE_SMALL;
}
 
Example 14
Source File: ScreenUtil.java    From PercentageChartView with Apache License 2.0 2 votes vote down vote up
/**
 * @param context Context instance
 * @return [true] if the device has a small screen, [false] otherwise.
 */
public static boolean hasSmallScreen(Context context) {
    return getScreenSize(context) == Configuration.SCREENLAYOUT_SIZE_SMALL;
}