header

 

More links

Adobe Connect | Adobe Conect Custom Pods | AutoHotkey | Android | Arduino | Blog | COMM140Fractals | Grammar Checkers | Knots | a Million Dots |  Processing | RedBubble | Tutorials | Weather | World Time Meeting Planner |



Home >Tutorials > Android Apps

>Chauffeurs Name Board Version 1 (no ads - no permissions)

Chauffeurs Name Board Version 1 (no ads - no permissions)

A simple app that allows Chauffeurs & Taxi drives to display the name of a passenger full screen on an Android phone or tablet.
I am selling it for AU 99c on Google Play.

 

Flash SMS Feature Graphic

 

My Java programming skills are very limited at the moment but I am happy to share the code for this app as it may be of use.

Please not that my Java coding style is very rough at the moment as I have lots to learn about good code style.

 

package au.id.rupert.chauffeurs_name_board;
// Version 2
// http://www.eigo.co.uk/labs/lock-screen-orientation-in-android/
// http://www.androidhive.info/2011/09/how-to-create-android-menus/

import android.os.Bundle;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.activity_main);
         this.setRequestedOrientation(
                 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        }

     // Initiating Menu XML file (menu.xml)
    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.layout.menu, menu);
        return true;
    }
    
    /**
     * Event Handling for Individual menu item selected
     * Identify single menu item by it's id
     * */

    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        final TextView textViewToChange = (TextView) findViewById(R.id.editText1);
        float TextSize = textViewToChange.getTextSize();
        float textScaleX = textViewToChange.getTextScaleX();
        
        Toast.makeText(MainActivity.this"First Text Scale X : " + Float.toString(textScaleX), Toast.LENGTH_SHORT).show();
        
        switch (item.getItemId())
        {
        case R.id.menu_larger:
            // Single menu item is selected do something
            // Toast.makeText(MainActivity.this, "Larger", Toast.LENGTH_SHORT).show();
            // Toast.makeText(MainActivity.this, "Larger: " + Float.toString(TextSize), Toast.LENGTH_SHORT).show();
            TextSize = textViewToChange.getTextSize();
            TextSize = TextSize + 20;
              textViewToChange.setTextSize(TypedValue.COMPLEX_UNIT_PX, TextSize);
              
            // textViewToChange.setTextSize(TextSize);

            return true;
 
        case R.id.menu_smaller:
            TextSize = textViewToChange.getTextSize();
            //  Toast.makeText(MainActivity.this, "Text Size before: " + Float.toString(TextSize), Toast.LENGTH_SHORT).show();  
            TextSize = TextSize - 20 ;
                // Toast.makeText(MainActivity.this, "Text Size after: " + Float.toString(TextSize), Toast.LENGTH_SHORT).show();  
            
            // Toast.makeText(MainActivity.this, "Smaller: " + Float.toString(TextSize), Toast.LENGTH_SHORT).show();         
            
            textViewToChange.setTextSize(TypedValue.COMPLEX_UNIT_PX, TextSize);
           // textViewToChange.setTextSize(TextSize);
            
            return super.onOptionsItemSelected(item);
        
        // STRETCH ===================================================================================================    
        case R.id.menu_stretch:
              //Toast.makeText(MainActivity.this, "stretch: " + Float.toString(TextSize), Toast.LENGTH_SHORT).show();    
              textScaleX = (float) (textScaleX + 0.1) ;
              textViewToChange.setTextScaleX(textScaleX);
              
            return true;
      
      // SHRINK ===================================================================================================         
      case R.id.menu_shrink:
              //Toast.makeText(MainActivity.this, "Shrink: " + Float.toString(TextSize), Toast.LENGTH_SHORT).show();     
            
              
            //  Toast.makeText(MainActivity.this, "Text Size before: " + Float.toString(TextSize), Toast.LENGTH_SHORT).show();  
              textScaleX = (float) (textScaleX - 0.1) ;
                // Toast.makeText(MainActivity.this, "Text Size after: " + Float.toString(TextSize), Toast.LENGTH_SHORT).show();  
            
            // Toast.makeText(MainActivity.this, "Smaller: " + Float.toString(TextSize), Toast.LENGTH_SHORT).show();         
            
            textViewToChange.setTextScaleX(textScaleX);
           // textViewToChange.setTextSize(TextSize);
            
            return super.onOptionsItemSelected(item);
        }
        return false;
    }    
}
Source Code
activity_main
    

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:layout_marginTop="29dp"
android:background="#000000">

<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="0.21"
android:ems="10"
android:background="#000000"
android:textColor="#ffffff"
android:hint="Type here"
android:textSize="180px"

android:textStyle="bold"
android:textScaleX="0.7"

android:typeface="serif"
android:inputType="textMultiLine|textCapWords"
android:cursorVisible="false"
>

</EditText>
</LinearLayout>
</RelativeLayout>

 

menu.xml
    <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Single menu item
Set id, icon and Title for each menu item
-->
<item android:id="@+id/menu_larger"
android:icon="@drawable/larger"
android:title="Larger" />

<item android:id="@+id/menu_smaller"
android:icon="@drawable/smaller"
android:title="Smaller" />

<item android:id="@+id/menu_stretch"
android:icon="@drawable/stretch"
android:title="Stretch" />

<item android:id="@+id/menu_shrink"
android:icon="@drawable/shrink"
android:title="Shrink" />


</menu>