DeviceUtils.java revision 5821806d5e7f356e8fa4b058a389a808ea183019
1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package org.chromium.content.browser;
6
7import android.content.Context;
8
9import org.chromium.content.common.CommandLine;
10
11/**
12 * A utility class that has helper methods for device configuration.
13 */
14public class DeviceUtils {
15
16    /**
17     * The minimum width that would classify the device as a tablet.
18     */
19    private static final int MINIMUM_TABLET_WIDTH_DP = 600;
20
21    /**
22     * @param context Android's context
23     * @return        Whether the app is should treat the device as a tablet for layout.
24     */
25    public static boolean isTablet(Context context) {
26        int minimumScreenWidthDp = context.getResources().getConfiguration().smallestScreenWidthDp;
27        return minimumScreenWidthDp >= MINIMUM_TABLET_WIDTH_DP;
28    }
29
30    /**
31     * Appends the switch specifying which user agent should be used for this device.
32     * @param contex The context for the caller activity.
33     */
34    public static void addDeviceSpecificUserAgentSwitch(Context context) {
35        if (isTablet(context)) {
36            CommandLine.getInstance().appendSwitch(CommandLine.TABLET_UI);
37        } else {
38            CommandLine.getInstance().appendSwitch(CommandLine.USE_MOBILE_UA);
39        }
40    }
41}
42