Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added getPhysicalSizeCategory() Ti.Platform.displayCaps for Android #2610

Merged
merged 3 commits into from
Jul 30, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
package ti.modules.titanium.platform;

import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiContext;

import android.os.Build;
import android.content.res.Configuration;

@Kroll.module(parentModule=PlatformModule.class)
public class AndroidModule extends PlatformModule{

@Kroll.constant public static final int API_LEVEL = Build.VERSION.SDK_INT;

@Kroll.constant public static final int PHYSICAL_SIZE_CATEGORY_UNDEFINED = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
@Kroll.constant public static final int PHYSICAL_SIZE_CATEGORY_SMALL = Configuration.SCREENLAYOUT_SIZE_SMALL;
@Kroll.constant public static final int PHYSICAL_SIZE_CATEGORY_NORMAL = Configuration.SCREENLAYOUT_SIZE_NORMAL;
@Kroll.constant public static final int PHYSICAL_SIZE_CATEGORY_LARGE = Configuration.SCREENLAYOUT_SIZE_LARGE;
@Kroll.constant public static final int PHYSICAL_SIZE_CATEGORY_XLARGE = 4; // Configuration.SCREENLAYOUT_SIZE_XLARGE (API 9)

@Kroll.getProperty @Kroll.method
public int getPhysicalSizeCategory() {
int size = TiApplication.getInstance().getApplicationContext().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
switch(size) {
case Configuration.SCREENLAYOUT_SIZE_SMALL :
case Configuration.SCREENLAYOUT_SIZE_NORMAL :
case Configuration.SCREENLAYOUT_SIZE_LARGE :
case 4 : // Configuration.SCREENLAYOUT_SIZE_XLARGE (API 9)
return size;
case Configuration.SCREENLAYOUT_SIZE_UNDEFINED:
default :
return PHYSICAL_SIZE_CATEGORY_UNDEFINED;
}
}

public AndroidModule()
{
super();
Expand Down
53 changes: 53 additions & 0 deletions apidoc/Titanium/Platform/Android/Android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,56 @@ properties:
[API levels](http://developer.android.com/guide/appendix/api-levels.html).
type: Number
permission: read-only

- name: PHYSICAL_SIZE_CATEGORY_LARGE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be overly picky, but I feel like these constants should be listed in a more natural way. IE: small, normal, large, xlarge, undefined

It can be easy for a user to look at values until they hit an error or undefined value and then stop since they assume they have hit the end of the list of "good" values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think alphabetical listings are the standard as I that's how it is throughout the rest of the docs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. I think the presentation would be better served by a usage type organization rather alphabetical but this is consistent so I will give on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it makes you feel any better, I originally typed it the way you are suggesting then changed it when I looked at the other constants in the docs. :)

summary: Constant to indicate that the physical size category of the current device/emulator is large
description: |
See the official Android Developers documentation for more information about
[large screen sizes](http://developer.android.com/reference/android/content/res/Configuration.html#SCREENLAYOUT_SIZE_LARGE)
type: Number
permission: read-only

- name: PHYSICAL_SIZE_CATEGORY_NORMAL
summary: Constant to indicate that the physical size category of the current device/emulator is normal
description: |
See the official Android Developers documentation for more information about
[normal screen sizes](http://developer.android.com/reference/android/content/res/Configuration.html#SCREENLAYOUT_SIZE_NORMAL)
type: Number
permission: read-only

- name: PHYSICAL_SIZE_CATEGORY_SMALL
summary: Constant to indicate that the physical size category of the current device/emulator is small
description: |
See the official Android Developers documentation for more information about
[small screen sizes](http://developer.android.com/reference/android/content/res/Configuration.html#SCREENLAYOUT_SIZE_SMALL)
type: Number
permission: read-only

- name: PHYSICAL_SIZE_CATEGORY_UNDEFINED
summary: Constant to indicate that the physical size category of the current device/emulator is undefined
description: |
See the official Android Developers documentation for more information about
[undefined screen sizes](http://developer.android.com/reference/android/content/res/Configuration.html#SCREENLAYOUT_SIZE_UNDEFINED)
type: Number
permission: read-only

- name: PHYSICAL_SIZE_CATEGORY_XLARGE
summary: Constant to indicate that the physical size category of the current device/emulator is extra large
description: |
See the official Android Developers documentation for more information about
[extra large screen sizes](http://developer.android.com/reference/android/content/res/Configuration.html#SCREENLAYOUT_SIZE_XLARGE)
type: Number
permission: read-only

- name: physicalSizeCategory
summary: |
The physical size category of the Android device or emulator.
description: |
It can be one of the following values:
- Ti.Platform.Android.PHYSICAL_SIZE_CATEGORY_SMALL
- Ti.Platform.Android.PHYSICAL_SIZE_CATEGORY_NORMAL
- Ti.Platform.Android.PHYSICAL_SIZE_CATEGORY_LARGE
- Ti.Platform.Android.PHYSICAL_SIZE_CATEGORY_XLARGE
- Ti.Platform.Android.PHYSICAL_SIZE_CATEGORY_UNDEFINED
type: Number
permission: read-only