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

How to Determine if Android Device Supports Faketouch Feature

public static final String FEATURE_FAKETOUCH was added in API level 11
Feature for getSystemAvailableFeatures() and hasSystemFeature(String): The device does not have a touch screen, but does support touch emulation for basic events. For instance, the device might use a mouse or remote control to drive a cursor, and emulate basic touch pointer events like down, up, drag, etc. All devices that support android.hardware.touchscreen or a sub-feature are presumed to also support faketouch.
Constant Value: "android.hardware.faketouch"

1. Get a PackageManager Instance and save to myPackageManager.

2. Create a Boolean Variable named bolFaketouchSupported. 

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

4. In the onCreate method, add the below code. This will return the faketouch ability to a boolean named bolFaketouchSupported. It will then display a toast displaying the faketouch ability on the device to the user.

bolFaketouchSupported = myPackageManager.hasSystemFeature(PackageManager.FEATURE_FAKETOUCH);
if (bolFaketouchSupported) {
Toast.makeText(this, "Device has Faketouch ability", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "No Faketouch ability!", Toast.LENGTH_LONG).show();
}

5. Compile and run!

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

android:translationY

added in API Level 11

translation in y of the view. This value is added post-layout to the left property of the view, which is set by its layout.

Ensure to change the minSDKVersion to 11, or greater.

       android:translationY

Related Articles:

Resources:

android:translationX

added in API Level 11

translation in x of the view. This value is added post-layout to the left property of the view, which is set by its layout.

Ensure to change the minSDKVersion to 11, or greater.

       android:translationX = "15px"

Related Articles:

Resources:

android:transformPivotY

android:transformPivotY was added in API Level 11

y location of the pivot point around which the view will rotate and scale. This XML attribute sets the pivotY property of the View.

Ensure to change the minSDKVersion to 11, or greater.

       android:transformPivotY = "0dp"

Related Articles:

Resources:

android:transformPivotX

added in API Level 11

x location of the pivot point around the view will rotate and scale. This xml attribute sets the pivotX property of the View.

Ensure to change the minSDKVersion to 11, or greater.

       android:transformPivotX = "0sp"


Related Articles:

Resources:

android:scaleY

added in API Level 11

scale of the view in the y direction.
A scaleY of 1 means no scaling is applied.

Ensure to change the minSDKVersion to 11, or greater.

       android:scaleY = ".5"

Related Articles:

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

android:scaleX

added in API Level 11

scale of the view in the x direction.
A scaleX of 1 means no scaling is applied.

Ensure to change the minSDKVersion to 11, or greater.

       android:scaleX = ".5"

Related Articles:

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

android:rotationY - Rotate a TextView/EditText on the y axis

How to Rotate a TextView/EditText on the y axis

added in API Level 11

rotation of the TextView/EditText around the y axis, in degrees. Rotates both the text and the TextView object.

To imagine how the rotationY works, take a spiral notebook and hold it directly in front of you, vertically, with spiral on left. You will see it looks like an exact rectangle. This is how a rotationY = 0 looks like.

Now slowly rotate the notebook backwards, while keeping the spiral edge in the same location. Move it about 45 degrees backwards. The paper will look like a sideways trapezoid from your perspective. The back edge will look shorter and the sides will move inward. (Like looking at railroad tracks, the tracks look like they are moving inwards towards each other.) This looks like a sideways trapezoid.

The closer you move it to 89 degrees, the smaller in height the sideways trapezoid will get and the closer the sides will appear.

At 90 degrees you would not be able to see what is on the paper, looking directly at it. It would be completely sideways.

Now, past 90 degrees, imagine that notebooks spiral is a clear piece of plastic with text on it. When the notebook is turned past 90 degrees, the text will turn upside, and appear backwards to you. However, now it looks like a inverted sideways trapezoid, up until 180 degrees.

At 180 degrees, it will be a square and the text upside down and backwards.

181 degrees to 269 degrees, the text will appear upside down and backwards, in a sideways trapezoid form.

At 270 degrees,  is like 90 degrees, it will be completely horizontal and you would not be able to see it.

271 to 359 degrees, text is right side up again, with a sideways trapezoid. The lower the number, the small in height the sideways trapezoid will appear.

If set to (175-185) degrees, will make the text upside down, and backwards. To read the text you would need a mirror.

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

2. Ensure to change the minSDKVersion to 11, or greater.

3. In the main.xml file, add the code below. This will rotate the TextView 45 degrees.

  <TextView
        ...
       android:rotationY = "45"
  />

4. Compile and run!

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

android:rotationX - Rotate a TextView/EditText on the x axis

How to Rotate a TextView/EditText on the x axis

added in API Level 11

rotation of the TextView/EditText around the x axis, in degrees. Rotates both the text and the TextView object.

To imagine how the rotationX works, take a spiral notebook and turn it on its side with the spiral on the bottom. Hold it directly in front of you, vertically, with the spiral on bottom. You will see it looks like an exact rectangle. This is how a rotationX = 0 looks like.

Now slowly rotate the notebook backwards, while keeping the spiral edge in the same location. Move it about 45 degrees backwards. The paper will look like a trapezoid from your perspective. The back edge will look shorter and the sides will move inward. (Like looking at railroad tracks, the tracks look like they are moving inwards towards each other.) This looks like a trapezoid.

The closer you move it to 89 degrees, the smaller in height the trapezoid will get and the closer the sides will appear.

At 90 degrees you would not be able to see what is on the paper, looking directly at it. It would be completely sideways.

Now, past 90 degrees, imagine that notebooks spiral is a clear piece of plastic with text on it. When the notebook is turned past 90 degrees, the text will turn upside, and appear backwards to you. However, now it looks like a inverted trapezoid, up until 180 degrees.

At 180 degrees, it will be a square and the text upside down and backwards.

181 degrees to 269 degrees, the text will appear upside down and backwards, in a trapezoid form.

At 270 degrees,  is like 90 degrees, it will be completely horizontal and you would not be able to see it.

271 to 359 degrees, text is right side up again, with a trapezoid. The lower the number, the small in height the trapezoid will appear.
 
If set to (175-185) degrees, will make the text upsize down, and backwards. To read the text you would need a mirror.

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

2. Ensure to change the minSDKVersion to 11, or greater.

3. In the main.xml file, add the code below. This will rotate the TextView 45 degrees.

  <TextView
        ...
       android:rotationX = "45"
  />

4. Compile and run!

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

android:rotation - Rotate a TextView/EditText

How to Rotate a TextView/EditText

added in API Level 11

rotation of the view, in degrees. Rotates both the text and the TextView object. If set to 180 degrees, will make the text upsize down. 90 degrees will make is vertical/sideways. Rotation starts from the middle of the TextView/EditView.

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

2. Ensure to change the minSDKVersion to 11, or greater.

3. In the main.xml file, add the code below. This will rotate the TextView 25 degrees.

  <TextView
        ...
       android:rotation = "25"
  />

4. Compile and run!

Related Articles:

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

android:nextFocusForward - Set Next Focus to TextView/EditText

How to Set Next Focus to a TextView/EditText

android:nextFocusForward was added in API Level 11

Defines the next view to give focus to when the next focus is FOCUS_FORWARD.
If the reference refers to a view that does not exist or is part of a hierarchy that is invisible, a RuntimeException will result when the reference is accessed.

1. Add 2 TextViews in your main.xml file.

2. Set the android:id of the first TextView to mySecondFocus, and the second TextView to myFirstFocus.

3. Ensure the minSDKVersion is, 11 or greater.

4. In the main.xml file, in the first TextView, add the code below.

  <TextView
        ...
       android:nextFocusForward = "@+id/myFirstFocus"
  />

5. In the second TextView, add the code below.

  <TextView
        ...
       android:nextFocusForward = "@+id/mySecondFocus"
  />

6. This will make the second TextView displayed on the screen the first focus, and the first TextView the second focus. 

7. Compile and run!

Related Articles:
Resources:

android:layerType

added in API Level 11

Specifies the type of layer backing this view. The default value is none.

Ensure to change the minSDKVersion to 11, or greater.

       android:layerType = "none"
       android:layerType = "software"
       android:layerType = "hardware"

none - Don't user a layer.
software - Use a software layer.
hardware - Use a hardware layer.

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

android:alpha - Set the Opacity/Transparency of Text in TextView/EditText

How to Set the Opacity/Transparency of Text in TextView/EditText

android:alpha was added in API Level 11

alpha property of the view, as a value between 0 (completely transparent) and 1 (completely opaque).
Must be a floating point value.
For a TextView and EditText this affects the text. If android:backgound is included, the background affected also.

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

2. Ensure to change the minSDKVersion to 11, or greater.

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

  <TextView
        ...
       android:alpha = ".5"
  />

4. Compile and run!

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

android:textIsSelectable - Select the Text in a TextView

How to Select the Text in a TextView

added in API Level 11

Indicates that the content of a non-editable TextView can be selected.
(An EditText is always selectable, so textIsSelectable is not necessary for an EditText.)
If you DO add android:textIsSelectable to a EditText the text IS selectable, but the field is NOT editable, nor is the cursor visible

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

2. Ensure the minSDKVersion is set to 11.

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

<TextView
        ...
       android:textIsSelectable = "true"
/>

4. Compile and run!

Resources:
http://developer.android.com/reference/android/widget/TextView.html#attr_android:textIsSelectable
http://developer.android.com/reference/android/R.attr.html#textIsSelectable

Hide/Remove the Action Bar from only one Activity screen

For API level 11 or greater

1. Add an Action Bar to your project.

2. Open the activity file you'd like to hide the Action Bar. We will use the MainActivity.java file for our example. Add the below import to the imports section.

import android.app.ActionBar; //Added in API level 11

3. While in the MainActivity.java file, add the below code to the onCreate method.

ActionBar bar = getActionBar();
bar.hide();

4. Compile and run!

Resources:
http://www.informit.com/articles/article.aspx?p=1743642&seqNum=5

Other Resources

How to Add a Contextual Action Bar(CAB)

API Level 11, or greater

1. Create an Options Menu using the below Items for the XML file.

Name: cmenu_action1
Title: Action 1

Name: cmenu_action2
Title: Action 2

Name: cmenu_action3
Title: Action 3

2. Ensure your minSdkVersion is 11, or greater. ActionMode was added in API level 11.

3. Open MainActivity.java file and add below lines to import section.

import android.view.ActionMode;
import android.view.MenuItem;
import android.view.ActionMode;
import android.view.View.OnLongClickListener;
 

4. Add the below 2 bolded lines between the public class and the onCreate method.

public class MainActivity extends Activity {

     ActionMode.Callback mCallback;    
     ActionMode mMode;    

 @Override    
  public void onCreate(Bundle savedInstanceState) {

5. Add this callback to your onCreate method. Make sure to add a Toast import.

@Override    
public void onCreate(Bundle savedInstanceState) {           
   super.onCreate(savedInstanceState);           
    setContentView(R.layout.activity_main); 

    mCallback = new ActionMode.Callback() {             
        @Override            
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) { 
               return false;            
        }            

         @Override            
         public void onDestroyActionMode(ActionMode mode) {  
              mMode = null;           
         }             


         @Override            
         public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                mode.setTitle("1 selected");
                getMenuInflater().inflate(R.menu.context_menu, menu); 
               return true; 
          }             

         @Override
         public boolean onActionItemClicked(ActionMode mode, MenuItem item) { 

               switch(item.getItemId()){
                    case R.id.cmenu_action1: 
                        Toast.makeText(getBaseContext(), "Selected Action1 ", Toast.LENGTH_LONG).show();
                    mode.finish();  
                    break; 
               case R.id.cmenu_action2:           
                   Toast.makeText(getBaseContext(), "Selected Action2 ", Toast.LENGTH_LONG).show(); 
                   break;        
                case R.id.cmenu_action3:               
                    Toast.makeText(getBaseContext(), "Selected Action3 ", Toast.LENGTH_LONG).show(); 
                   break; 
               }  
              return false;  
          }     
  };



 OnLongClickListener listener = new OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                if(mMode!=null)
                    return false;
                else
                    mMode = startActionMode(mCallback);
                    return true;
                
             }
        };

6. Compile and test.

Resources:
http://developer.android.com/design/patterns/actionbar.html
http://wptrafficanalyzer.in/blog/creating-a-contextual-menu-bar-contextual-action-mode-for-a-single-view-in-android/
http://developer.android.com/reference/android/view/ActionMode.html