Showing posts with label API Level 17. Show all posts
Showing posts with label API Level 17. Show all posts

How to Determine if Android Device has a Camera

public static final String FEATURE_CAMERA_ANY was added in API level 17
Feature for getSystemAvailableFeatures() and hasSystemFeature(String).
The device has at least one camera pointing in some direction.
Constant Value: "android.hardware.camera.any"

1. Get a PackageManager Instance and save to myPackageManager.

2. Create a Boolean Variable named bolCameraSupported

3. Set the Minimum and Target SDK version  to 17 or greater. 

4. In the onCreate method, add the below code. This will return the any camera support to a boolean named bolCameraSupported. It will then display a toast displaying the camera existence on the device to the user.

bolCameraSupported = myPackageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY);
if (bolCameraSupported) {
Toast.makeText(this, "Device has at least 1 Camera", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "No Camera on Device!", Toast.LENGTH_LONG).show();
}

5. Compile and run!

Resources:
http://developer.android.com/reference/android/content/pm/PackageManager.html#FEATURE_CAMERA_ANY

setCompoundDrawablesRelativeWithIntrinsicBounds/android:drawableStart - Add a Drawable to the Start of Text, in a TextView, in Java

setCompoundDrawablesRelativeWithIntrinsicBounds - How to Add a Drawable to the Start of Text, in a TextView, in Java

setCompoundDrawablesRelativeWithIntrinsicBounds was added in API Level 17
Related XML Attribute: android:drawableStart

setCompoundDrawablesRelativeWithIntrinsicBounds (int start, int top, int end, int bottom)Sets the Drawables (if any) to appear to the start of, above, to the end of, and below the text. Use 0 if you do not want a Drawable there. The Drawables' bounds will be set to their intrinsic bounds.

1. Ensure to change the minSDKVersion to 17, or greater.


4. Add the code below to the onCreate method. This will set a drawable to be drawn to the end of the text. 
    myTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.myImage,0,0,0);
5. Compile and run!

setCompoundDrawablesRelativeWithIntrinsicBounds/android:drawableEnd - Add a Drawable to the End of Text, in a TextView, in Java

setCompoundDrawablesRelativeWithIntrinsicBounds - How to Add a Drawable to the end of Text, in a TextView, in Java

setCompoundDrawablesRelativeWithIntrinsicBounds was added in API Level 17
Related XML Attribute: android:drawableEnd

setCompoundDrawablesRelativeWithIntrinsicBounds (int start, int top, int end, int bottom)Sets the Drawables (if any) to appear to the start of, above, to the end of, and below the text. Use 0 if you do not want a Drawable there. The Drawables' bounds will be set to their intrinsic bounds.

1. Ensure to change the minSDKVersion to 17, or greater.


3. Add a drawable named myImage

4. Add the code below to the onCreate method. This will set a drawable to be drawn to the end of the text. 
    myTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(0,0,R.drawable.myImage,0);
5. Compile and run!

android:textDirection

How to Title Here

added in API Level 17

Defines the direction of the text. A heuristic is used to determine the resolved text direction of paragraphs.

Ensure to change the minSDKVersion to 17, or greater.

       android:textDirection = "rtl"

inherit - Default
firstStrong - Default for the root view. The first strong directional character determines the paragraph direction. If there is no strong directional character, the paragraph direction is the view's resolved layout direction.
anyRtl - The paragraph direction is RTL if it contains any strong RTL character, otherwise it is LTR if it contains any strong LTR characters. If there are neither, the paragraph direction is the view's resolved layout direction.
ltr - The paragraph direction is left to right.
rtl - The paragraph direction is right to left.
locale - The paragraph direction is coming from the system Locale.

Related Articles:

Resources:

android:textAlignment

added in API Level 17

Defines the alignment of the text. A heuristic is used to determine the resolved text alignment.

Ensure to change the minSDKVersion to 17, or greater.

android:textAlignment = "textStart"

inherit - Default
gravity - Default for root view. The gravity determines the alignment, ALIGN_NORMAL, ALIGN_CENTER, or ALIGN_OPPOSITE, which are relative to each paragraph's text direction.
textStart - Align to the start of the paragraph, e.g. ALIGN_NORMAL.
textEnd - Align to the end of the paragraph, e.g. ALIGN_OPPOSITE.
center - Center the paragraph, e.g. ALIGN_CENTER.
viewStart - Align to the start of the view, which is ALIGN_LEFT if the view's resolved layoutDirection is LTR, and ALIGN_RIGHT otherwise.
viewEnd - Align to the end of the view, which is ALIGN_RIGHT if the view's resolved layoutDirection is LTR, and ALIGN_LEFT otherwise.

Related Articles:

Resources:

android:paddingStart - Set the Padding at the Start Edge of a TextView/EditText

How to Set the Padding at the Start Edge of  a TextView/EditText

added in API Level 17

Sets the padding, in pixels, at the start edge. Padding is defined as space between the edges of the view and the view's content. A view size will include it's padding.

1. Add a TextView in your main.xml file.

2. Ensure the minSDKVersion is, 17 or greater.

3. In the main.xml file, add the code below.

  <TextView
        ...
       android:paddingStart = "50sp"
  />

4. Compile and run!

Related Articles:
Resources:
http://developer.android.com/reference/android/view/View.html#attr_android:paddingEnd
http://developer.android.com/reference/android/R.attr.html#paddingEnd

android:paddingEnd - Set the Padding on the Edge of a TextView/EditText

How to Set the Padding on the Edge of  a TextView/EditText

android:paddingEnd was added in API Level 17

Sets the padding, in pixels, of the end edge. Padding is defined as space between the edges of the view and the view's content. A view size will include it's padding.

1. Add a TextView in your main.xml file.

2. Ensure the minSDKVersion is, 17 or greater.

3. In the main.xml file, add the code below.

  <TextView
        ...
       android:paddingEnd = "50sp"
  />

4. Compile and run!

Related Articles:
Resources:
http://developer.android.com/reference/android/view/View.html#attr_android:paddingEnd
http://developer.android.com/reference/android/R.attr.html#paddingEnd

android:layoutDirection

added in API Level 17

Defines the direction of layout drawing. This typically is associated with writing direction of the language script used. If there is nothing to inherit, "locale" is used. "locale" falls back to "en-US". "ltr" is the direction used in "en-US". The default for this attribute is "inherit".

Ensure to change the minSDKVersion to 17, or greater.

       android:layoutDirection = "ltr"
       android:layoutDirection = "rtl"
       android:layoutDirection = "inherit"
       android:layoutDirection = "locale"

ltr - Left-to-Right
rtl - Right-to-Left
inherit - Inherit from parent
locale - Locale

Resources:
http://developer.android.com/reference/android/view/View.html#attr_android:layoutDirection
http://developer.android.com/reference/android/R.attr.html#layoutDirection