Home | History | Annotate | Download | only in snippets
      1 <?xml version="1.0" encoding="UTF-8"?>
      2 <?eclipse version="3.2"?>
      3 <plugin>
      4    <extension
      5          point="org.eclipse.ui.startup">
      6       <startup
      7             class="com.motorola.studio.android.codesnippets.AndroidSnippetsStartup"></startup>
      8    </extension>
      9    <extension point="org.eclipse.wst.common.snippets.SnippetContributions">
     10     <category
     11           description="%category.service.description"
     12           id="android_services"
     13           label="%category.service">
     14        <item
     15              class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
     16              description="%snippet.service.systemService00.description"
     17              id="com.motorola.studio.android.codesnippets.item3"
     18              label="%snippet.service.systemService00">
     19           <content>
     20              // To use this ActivityManager method, AndroidManifest.xml must have the following permission:
     21 //&lt;uses-permission android:name=&quot;android.permission.GET_TASKS&quot;/&gt;
     22 ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
     23           </content>
     24        </item>
     25        <item
     26              description="%snippet.service.systemService01.description"
     27              id="com.motorola.studio.android.codesnippets.item4"
     28              label="%snippet.service.systemService01">
     29           <content>
     30              AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
     31           </content>
     32        </item>
     33        <item
     34              description="%snippet.service.systemService02.description"
     35              id="com.motorola.studio.android.codesnippets.item5"
     36              label="%snippet.service.systemService02">
     37           <content>
     38              AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
     39           </content>
     40        </item>
     41        <item
     42              description="%snippet.service.systemService03.description"
     43              id="com.motorola.studio.android.codesnippets.item6"
     44              label="%snippet.service.systemService03">
     45           <content>
     46              ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
     47           </content>
     48        </item>
     49        <item
     50        class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
     51              description="%snippet.service.systemService04.description"
     52              id="com.motorola.studio.android.codesnippets.item7"
     53              label="%snippet.service.systemService04">
     54           <content>
     55              // To use this ConectivityManager method, AndroidManifest.xml must have the following permission:
     56 // &lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot;/&gt;
     57 ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
     58           </content>
     59        </item>
     60        <item
     61              description="%snippet.service.systemService05.description"
     62              id="com.motorola.studio.android.codesnippets.item8"
     63              label="%snippet.service.systemService05">
     64           <content>
     65              InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
     66           </content>
     67        </item>
     68        <item
     69              description="%snippet.service.systemService06.description"
     70              id="com.motorola.studio.android.codesnippets.item9"
     71              label="%snippet.service.systemService06">
     72           <content>
     73              KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
     74           </content>
     75        </item>
     76        <item
     77              description="%snippet.service.systemService07.description"
     78              id="com.motorola.studio.android.codesnippets.item10"
     79              label="%snippet.service.systemService07">
     80           <content>
     81              LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     82           </content>
     83        </item>
     84        <item
     85              description="%snippet.service.systemService08.description"
     86              id="com.motorola.studio.android.codesnippets.item11"
     87              label="%snippet.service.systemService08">
     88           <content>
     89              LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
     90           </content>
     91        </item>
     92        <item
     93              description="%snippet.service.systemService09.description"
     94              id="com.motorola.studio.android.codesnippets.item12"
     95              label="%snippet.service.systemService09">
     96           <content>
     97              NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
     98           </content>
     99        </item>
    100        <item
    101        class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
    102              description="%snippet.service.systemService10.description"
    103              id="com.motorola.studio.android.codesnippets.item13"
    104              label="%snippet.service.systemService10">
    105           <content>
    106              // To use this PowerManager method, AndroidManifest.xml must have the following permission:
    107 // &lt;uses-permission android:name=&quot;android.permission.DEVICE_POWER&quot;/&gt;
    108 PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    109           </content>
    110        </item>
    111        <item
    112              description="%snippet.service.systemService11.description"
    113              id="com.motorola.studio.android.codesnippets.item14"
    114              label="%snippet.service.systemService11">
    115           <content>
    116              SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    117           </content>
    118        </item>
    119        <item
    120              description="%snippet.service.systemService12.description"
    121              id="com.motorola.studio.android.codesnippets.item15"
    122              label="%snippet.service.systemService12">
    123           <content>
    124              SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    125           </content>
    126        </item>
    127        <item
    128        class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
    129              description="%snippet.service.systemService13.description"
    130              id="com.motorola.studio.android.codesnippets.item32"
    131              label="%snippet.service.systemService13">
    132           <content>
    133              // To use this TelephonyManager method, AndroidManifest.xml must have the following permission:
    134 // &lt;uses-permission android:name=&quot;android.permission.READ_PHONE_STATE&quot;/&gt;
    135 TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    136           </content>
    137        </item>
    138        <item
    139        class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
    140              description="%snippet.service.systemService14.description"
    141              id="com.motorola.studio.android.codesnippets.item33"
    142              label="%snippet.service.systemService14">
    143           <content>
    144              // To use this Vibrator method, AndroidManifest.xml must have the following permission:
    145 // &lt;uses-permission android:name=&quot;android.permission.VIBRATE&quot;/&gt;
    146 Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    147           </content>
    148        </item>
    149        <item
    150        class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
    151              description="%snippet.service.systemService15.description"
    152              id="com.motorola.studio.android.codesnippets.item34"
    153              label="%snippet.service.systemService15">
    154           <content>
    155              // To use this WallpaperService method, AndroidManifest.xml must have the following permission:
    156 // &lt;uses-permission android:name=&quot;android.permission.SET_WALLPAPER&quot;/&gt;
    157 WallpaperService wallpaperService = (WallpaperService) getSystemService(Context.WALLPAPER_SERVICE);
    158           </content>
    159        </item>
    160        <item
    161        class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
    162              description="%snippet.service.systemService16.description"
    163              id="com.motorola.studio.android.codesnippets.item35"
    164              label="%snippet.service.systemService16">
    165           <content>
    166              // To use this WifiManager method, AndroidManifest.xml must have the following permission:
    167 // &lt;uses-permission android:name=&quot;android.permission.ACCESS_WIFI_STATE&quot;/&gt;
    168 WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    169           </content>
    170        </item>
    171        <item
    172              description="%snippet.service.systemService17.description"
    173              id="com.motorola.studio.android.codesnippets.item36"
    174              label="%snippet.service.systemService17">
    175           <content>
    176              WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    177           </content>
    178        </item>
    179     </category>         
    180 		
    181 		
    182 		
    183 		<category
    184         description="%category.general.description"
    185         id="android_general"
    186         label="%category.general">
    187         <item
    188         class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
    189               description="%snippet.general.sendSMS.description"
    190               id="com.motorola.studio.android.codesnippets.item9"
    191               label="%snippet.general.sendSMS">
    192            <content>
    193               // To use these SmsManager methods, AndroidManifest.xml must have the following permission:
    194 // &lt;uses-permission android:name=&quot;android.permission.SEND_SMS&quot;/&gt;
    195 SmsManager m = SmsManager.getDefault();
    196 String destinationNumber =&quot;0123456789&quot;;  
    197 String text = &quot;Hello!&quot;;  
    198 m.sendTextMessage(destinationNumber, null, text, null, null);
    199            </content>
    200         </item>
    201         <item
    202               description="%snippet.general.toast.description"
    203               id="com.motorola.studio.android.codesnippets.item8"
    204               label="%snippet.general.toast">
    205            <content>
    206               Toast.makeText(this, &quot;Put your message here&quot;, Toast.LENGTH_SHORT).show();
    207            </content>
    208         </item>
    209         <item
    210               description="%snippet.general.statusBar.description"
    211               id="com.motorola.studio.android.codesnippets.item31"
    212               label="%snippet.general.statusBar">
    213            <content>
    214               int notificationID = 10;
    215 NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    216 // Create the notification
    217 Notification notification = new Notification(R.drawable.yourIconId, &quot;Put your notification text here&quot;, System.currentTimeMillis());
    218 // Create the notification's expanded message
    219 // When the user clicks on it, it opens your activity
    220 Intent intent = new Intent(this, YourActivityName.class);
    221 PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
    222 notification.setLatestEventInfo(this, &quot;Put your title here&quot;, &quot;Put your text here&quot;, pendingIntent);
    223 // Show notification
    224 notificationManager.notify(notificationID, notification);
    225            </content>
    226         </item>
    227         <item
    228         class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
    229               description="%snippet.general.vibrateTime.description"
    230               id="com.motorola.studio.android.codesnippets.item6"
    231               label="%snippet.general.vibrateTime">
    232            <content>
    233               // To use these Vibrator methods, AndroidManifest.xml must have the following permission:
    234 // &lt;uses-permission android:name=&quot;android.permission.VIBRATE&quot;/&gt;
    235 // Vibrate for 1 second
    236 Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); 
    237 vibrator.vibrate(1000);
    238            </content>
    239         </item>
    240         <item
    241         class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
    242               description="%snippet.general.vibratePattern.description"
    243               id="com.motorola.studio.android.codesnippets.item25"
    244               label="%snippet.general.vibratePattern">
    245            <content>
    246 // To use these Vibrator methods, AndroidManifest.xml must have the following permission:
    247 //&lt;uses-permission android:name=&quot;android.permission.VIBRATE&quot;/&gt;
    248 // Vibrate in a pattern with 0ms off(start immediately), 200ms on, 100ms off, 100ms on, 500ms off, 500ms on,
    249 // repeating the pattern starting from index 4: 100ms on. 
    250 // Note that you'll have to call vibrator.cancel() in order to stop the vibrator.
    251 // Change the second parameter to -1 if you want play the pattern only once. 
    252 Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    253 vibrator.vibrate(new long[] {0, 200, 100, 100, 500, 500}, 4);
    254            </content>
    255         </item>
    256         <item
    257         class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
    258               description="%snippet.general.strictMode.description"
    259               id="com.motorola.studio.android.codesnippets.item25"
    260               label="%snippet.general.strictMode">
    261            <content>
    262         // Add or remove any policies and penalties strict mode checking.
    263         // This is for application development and testing and should be
    264         // removed before your application reaches the market.
    265         // For more details of what each method does, check
    266         // http://developer.android.com/reference/android/os/StrictMode.ThreadPolicy.Builder.html
    267 		StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
    268                  .detectDiskReads()
    269                  .detectDiskWrites()
    270                  .detectNetwork()   // or .detectAll() for all detectable problems
    271                  .penaltyDialog() 
    272                  .penaltyLog()	
    273                  .build());
    274          StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
    275                  .detectLeakedSqlLiteObjects()
    276                  .penaltyLog() 
    277                  .penaltyDeath() 
    278                  .build());
    279          // you can also use the penaltyDropBox() as an alternative to displaying a violation occurrence
    280            </content>
    281         </item>
    282 		 </category>
    283 		 
    284 		 
    285 		 
    286 		 
    287 	   <category
    288           description="%category.database.description"
    289           id="android_database"
    290           label="%category.database">
    291        <item
    292              description="%snippet.database.createOrOpenDb.description"
    293              id="com.motorola.studio.android.codesnippets.item29"
    294              label="%snippet.database.createOrOpenDb">
    295           <content>
    296              SQLiteDatabase db =openOrCreateDatabase(&quot;MyDatabaseName&quot;, MODE_PRIVATE, null);
    297           </content>
    298        </item>
    299        <item
    300              description="%snippet.database.deleteDb.description"
    301              id="com.motorola.studio.android.codesnippets.item5"
    302              label="%snippet.database.deleteDb">
    303           <content>
    304              boolean success = deleteDatabase(&quot;MyDatabaseName&quot;);
    305           </content>
    306        </item>
    307        <item
    308              description="%snippet.database.createTbl.description"
    309              id="com.motorola.studio.android.codesnippets.item17"
    310              label="%snippet.database.createTbl">
    311           <content>
    312              db.execSQL(&quot;CREATE TABLE MyTableName (_id INTEGER PRIMARY KEY AUTOINCREMENT, YourColumnName TEXT);&quot;);
    313           </content>
    314        </item>
    315        <item
    316              description="%snippet.database.deleteTbl.description"
    317              id="com.motorola.studio.android.codesnippets.item18"
    318              label="%snippet.database.deleteTbl">
    319           <content>
    320              db.execSQL(&quot;DROP TABLE IF EXISTS MyTableName&quot;);
    321           </content>
    322        </item>
    323        <item
    324              description="%snippet.database.insertEntry.description"
    325              id="com.motorola.studio.android.codesnippets.item20"
    326              label="%snippet.database.insertEntry">
    327           <content>
    328              // Since SQL doesn&apos;t allow the insertion of a completely empty row, the second parameter of db.insert defines the column that will receive NULL if cv is empty
    329 ContentValues cv=new ContentValues();
    330 cv.put(&quot;YourColumnName&quot;, &quot;YourColumnValue&quot;);
    331 db.insert(&quot;MyTableName&quot;, &quot;YourColumnName&quot;, cv);
    332           </content>
    333        </item>
    334        <item
    335              description="%snippet.database.updateEntry.description"
    336              id="com.motorola.studio.android.codesnippets.item21"
    337              label="%snippet.database.updateEntry">
    338           <content>
    339              ContentValues cv=new ContentValues();
    340 cv.put(&quot;YourColumnName&quot;, &quot;YourColumnValue&quot;);
    341 db.update(&quot;MyTableName&quot;, cv, &quot;_id=?&quot;, new String[]{&quot;1&quot;});
    342           </content>
    343        </item>
    344        <item
    345              description="%snippet.database.deleteEntry.description"
    346              id="com.motorola.studio.android.codesnippets.item22"
    347              label="%snippet.database.deleteEntry">
    348           <content>
    349              db.delete(&quot;MyTableName&quot;,&quot;_id=?&quot;, new String[]{&quot;1&quot;});
    350           </content>
    351        </item>
    352        <item
    353              description="%snippet.database.runQuery.description"
    354              id="com.motorola.studio.android.codesnippets.item23"
    355              label="%snippet.database.runQuery">
    356           <content>
    357              Cursor c=db.rawQuery(SQL_COMMAND, null);
    358           </content>
    359        </item>
    360        </category>
    361        
    362        
    363        
    364        
    365        
    366        <category
    367              description="%category.menus.description"
    368              id="android_menus"
    369              label="%category.menus">
    370        <item
    371              description="%snippet.menus.handleItems.description"
    372              id="com.motorola.studio.android.codesnippets.item3"
    373              label="%snippet.menus.handleItems">
    374           <content>
    375              /*
    376 * Add this in your Activity
    377 */
    378 private final int MENU_ITEM_0 = 0;  
    379 private final int MENU_ITEM_1 = 1;  
    380  
    381 
    382 /** 
    383  * Add menu items
    384  * 
    385  * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
    386  */
    387 public boolean onCreateOptionsMenu(Menu menu) {  
    388     menu.add(0, MENU_ITEM_0, 0, &quot;Menu Item 0&quot;);  
    389     menu.add(0, MENU_ITEM_1, 0, &quot;Menu Item 1&quot;);  
    390     return true;  
    391 }  
    392  
    393 /** 
    394  * Define menu action
    395  * 
    396  * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
    397  */
    398 public boolean onOptionsItemSelected(MenuItem item) {  
    399     switch (item.getItemId()) {  
    400         case MENU_ITEM_0:  
    401         	// put your code here 
    402         	break;
    403         case MENU_ITEM_1: 
    404         	// put your code here 
    405         	break;
    406 	  default:
    407 		// put your code here	  
    408     }  
    409     return false;  
    410 }
    411           </content>
    412        </item>
    413        <item
    414              description="%snippet.menus.disableItem.description"
    415              id="com.motorola.studio.android.codesnippets.item2"
    416              label="%snippet.menus.disableItem">
    417           <content>
    418              menu.findItem(&quot;yourItemId&quot;).setEnabled(false);
    419           </content>
    420        </item>
    421        <item
    422              description="%snippet.menus.subItem.description"
    423              id="com.motorola.studio.android.codesnippets.item3"
    424              label="%snippet.menus.subItem">
    425           <content>
    426              SubMenu subMenu = menu.addSubMenu(&quot;YourMenu&quot;);
    427 			 subMenu.add(&quot;YourSubMenu1&quot;);
    428              
    429           </content>
    430        </item>
    431        <item
    432              description="%snippet.menus.declareMenuXML.description"
    433              id="com.motorola.studio.android.codesnippets.item4"
    434              label="%snippet.menus.declareMenuXML">
    435           <content>
    436              &lt;menu xmlns:android=&quot;http://schemas.android.com/apk/res/android">;
    437     &lt;item android:id=&quot;@+id/menu_0&quot;
    438           android:title=&quot;Menu Item 0&quot; /&gt;
    439     &lt;item android:id=&quot;@+id/menu_1&quot;
    440           android:title=&quot;Menu Item 1&quot; /&gt;
    441 &lt;/menu&gt;
    442           </content>
    443        </item>
    444        <item
    445              description="%snippet.menus.inflateMenu.description"
    446              id="com.motorola.studio.android.codesnippets.item5"
    447              label="%snippet.menus.inflateMenu">
    448           <content>
    449              /**
    450 * Inflate Menu from XML
    451 */
    452 public boolean onCreateOptionsMenu(Menu menu) {
    453     super.onCreateOptionsMenu(menu);
    454     MenuInflater inflater = getMenuInflater();
    455     inflater.inflate(R.menu.yourXMLName, menu);
    456     return true;
    457 }
    458           </content>
    459        </item>
    460        <item
    461              description="%snippet.menus.showActionBar.description"
    462              id="com.motorola.studio.android.codesnippets.item6"
    463              label="%snippet.menus.showActionBar">
    464           <content>
    465              //Notes: 
    466 // - The Action Bar was introduced in API level 11.
    467 //    If you set minSDKVersion &lt; 11 or targetSDKVersion &lt; 11 or 
    468 //    if you do not set any of these, getActionBar() will return null. 
    469 // - If you removed the Action Bar using a theme,
    470 //   getActionBar() will return null.
    471 if (getActionBar() != null){
    472 	getActionBar().show();
    473 }
    474           </content>
    475        </item>
    476        <item
    477              description="%snippet.menus.hideActionBar.description"
    478              id="com.motorola.studio.android.codesnippets.item7"
    479              label="%snippet.menus.hideActionBar">
    480           <content>
    481              //Notes: 
    482 // - The Action Bar was introduced in API level 11.
    483 //    If you set minSDKVersion &lt; 11 or targetSDKVersion &lt; 11 or 
    484 //    if you do not set any of these, getActionBar() will return null. 
    485 // - If you removed the Action Bar using a theme,
    486 //   getActionBar() will return null.
    487 if (getActionBar() != null){
    488 	getActionBar().hide();
    489 }
    490           </content>
    491        </item>
    492        <item
    493              description="%snippet.menus.toggle.actionbar.description"
    494              id="com.motorola.studio.android.codesnippets.item9"
    495              label="%snippet.menus.toggle.actionbar.label">
    496           <content>
    497              //Toggles action bar state (If visible, hides it. If hidden, shows it)
    498 ActionBar bar = getActionBar();
    499 if (bar != null) {
    500 	if (bar.isShowing()) {
    501 		bar.hide();
    502 	}
    503 	else {
    504 		bar.show();
    505 	}
    506 }
    507           </content>
    508        </item>
    509        <item
    510              description="%snippet.menus.manage.actionbar.description"
    511              id="com.motorola.studio.android.codesnippets.item8"
    512              label="%snippet.menus.manage.actionbar.label">
    513           <content>
    514              //Sets the action bar navigation mode
    515 ActionBar actionBar = getActionBar();
    516 actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    517           </content>
    518        </item>
    519     </category>
    520     <category
    521           description="%category.dialogs.description"
    522           id="android_dialogs"
    523           label="%category.dialogs">
    524        <item
    525              description="%snippet.dialogs.alert.description"
    526              id="com.motorola.studio.android.codesnippets.item26"
    527              label="%snippet.dialogs.alert">
    528           <content>
    529              AlertDialog.Builder builder = new AlertDialog.Builder(this);
    530 builder.setMessage(&quot;Put your question here?&quot;)
    531        .setCancelable(false)
    532        .setPositiveButton(&quot;Yes&quot;, new DialogInterface.OnClickListener() {
    533            public void onClick(DialogInterface dialog, int id) {
    534                 // put your code here
    535            }
    536        })
    537        .setNegativeButton(&quot;No&quot;, new DialogInterface.OnClickListener() {
    538            public void onClick(DialogInterface dialog, int id) {
    539         	   // put your code here 
    540         	   dialog.cancel();
    541            }
    542        });
    543 AlertDialog alertDialog = builder.create();
    544 alertDialog.show();
    545           </content>
    546        </item>
    547        <item
    548              description="%snippet.dialogs.progressDialog"
    549              id="com.motorola.studio.android.codesnippets.item27"
    550              label="%snippet.dialogs.progressDialog">
    551           <content>
    552              ProgressDialog dialog = ProgressDialog.show(this, &quot;Your Title&quot;, &quot;Put your message here&quot;, true);
    553           </content>
    554        </item>
    555        <item
    556              description="%snippet.dialogs.progressBar.description"
    557              id="com.motorola.studio.android.codesnippets.item29"
    558              label="%snippet.dialogs.progressBar">
    559           <content>
    560              ProgressDialog progressDialog = new ProgressDialog(this);
    561 progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    562 progressDialog.setMax(PROGRESS_MAX);
    563 progressDialog.setMessage(&quot;Put your message here&quot;);
    564 progressDialog.setCancelable(false);
    565 progressDialog.incrementProgressBy(PROGRESS_INCREMENT);
    566           </content>
    567        </item>
    568        <item
    569              description="%snippet.dialogs.datePicker.description"
    570              id="com.motorola.studio.android.codesnippets.item28"
    571              label="%snippet.dialogs.datePicker">
    572           <content>
    573              // Define the date picker dialog listener, which will be called after
    574 // the user picks a date in the displayed dialog
    575 DatePickerDialog.OnDateSetListener datePickerDialogListener =
    576     new DatePickerDialog.OnDateSetListener() {
    577 
    578         public void onDateSet(DatePicker view, int year, 
    579                               int monthOfYear, int dayOfMonth) {
    580             // put your code here
    581         	// update your model/view with the date selected by the user
    582         }
    583     };
    584 
    585 // Get the current date
    586 Calendar calendar = Calendar.getInstance();
    587 int year = calendar.get(Calendar.YEAR);
    588 int month = calendar.get(Calendar.MONTH);
    589 int day = calendar.get(Calendar.DAY_OF_MONTH);
    590 
    591 // Create a date picker dialog
    592 DatePickerDialog datePickerDialog = new DatePickerDialog(this,
    593 		datePickerDialogListener,
    594 		year, month, day);
    595 
    596 // Display the date picker dialog
    597 datePickerDialog.show();
    598              
    599           </content>
    600        </item>
    601        <item
    602              description="%snippet.dialogs.timePicker.description"
    603              id="com.motorola.studio.android.codesnippets.item25"
    604              label="%snippet.dialogs.timePicker">
    605           <content>
    606              // Define the date picker dialog listener, which will be called after
    607 // the user picks a time in the displayed dialog
    608 TimePickerDialog.OnTimeSetListener timePickerDialogListener =
    609     new TimePickerDialog.OnTimeSetListener() {
    610         public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
    611         	// put your code here
    612         	// update your model/view with the date selected by the user
    613         }
    614     };
    615 
    616 // Get the current time
    617 Calendar c = Calendar.getInstance();
    618 int hour = c.get(Calendar.HOUR_OF_DAY);
    619 int minute = c.get(Calendar.MINUTE);
    620 
    621 // Create a time picker dialog
    622 TimePickerDialog timerPickerDialog = new TimePickerDialog(this,
    623 		timePickerDialogListener, hour, minute, false);
    624 
    625 // Display the time picker dialog
    626 timerPickerDialog.show();
    627              
    628           </content>
    629        </item>
    630        <item
    631              description="%snippet.dialogs.custom.description"
    632              id="com.motorola.studio.android.codesnippets.item30"
    633              label="%snippet.dialogs.custom">
    634           <content>
    635              Dialog dialog = new Dialog(this);
    636 dialog.setContentView(R.layout.yourLayoutId);
    637 dialog.show();
    638              
    639           </content>
    640        </item>
    641        <item
    642              id="com.motorola.studio.android.codesnippets.item9"
    643              label="%snippet.dialogs.customAlert">
    644           <content>
    645              LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    646 View layout = inflater.inflate(R.layout.yourLayoutId, (ViewGroup) findViewById(R.id.yourLayoutRoot));
    647 AlertDialog.Builder builder = new AlertDialog.Builder(this)
    648 	.setView(layout);
    649 AlertDialog alertDialog = builder.create();
    650 alertDialog.show();
    651              
    652           </content>
    653        </item>
    654     </category>
    655     
    656     
    657     
    658     
    659     <category
    660           description="%category.screen.description"
    661           id="android_screen"
    662           label="%category.screen">
    663        <item
    664              description="%snippet.screen.fullscreen.description"
    665              id="com.motorola.studio.android.codesnippets.item5"
    666              label="%snippet.screen.fullscreen">
    667           <content>
    668              getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    669           </content>
    670        </item>
    671        <item
    672              description="%snippet.screen.size.description"
    673              id="com.motorola.studio.android.codesnippets.item24"
    674              label="%snippet.screen.size">
    675           <content>
    676              Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
    677 int width = display.getWidth();  
    678 int height = display.getHeight();
    679           </content>
    680        </item>
    681        <item
    682              description="%snippet.screen.orientation.description"
    683              id="com.motorola.studio.android.codesnippets.item1"
    684              label="%snippet.screen.orientation">
    685           <content>
    686              Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
    687 int orientation = display.getOrientation();
    688           </content>
    689        </item>
    690     </category>
    691     <category
    692           description="%category.gps.description"
    693           id="android_gps"
    694           label="%category.gps">
    695        <item
    696        class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
    697              description="%snippet.gps.currentCoordinates.description"
    698              id="com.motorola.studio.android.codesnippets.item6"
    699              label="%snippet.gps.currentCoordinates">
    700           <content>
    701              // To use these LocationManager methods, AndroidManifest.xml must have the following permission:
    702 // &lt;uses-permission android:name=&quot;android.permission.ACCESS_FINE_LOCATION&quot;/&gt;
    703 LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    704 locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {
    705 	public void onStatusChanged(String provider, int status, Bundle extras) {
    706 		// called when the location provider status changes. Possible status: OUT_OF_SERVICE, TEMPORARILY_UNAVAILABLE or AVAILABLE.
    707 	}
    708 	public void onProviderEnabled(String provider) {
    709 		// called when the location provider is enabled by the user
    710 	}
    711 	public void onProviderDisabled(String provider) {
    712 		// called when the location provider is disabled by the user. If it is already disabled, it&apos;s called immediately after requestLocationUpdates
    713 	}
    714 	
    715 	public void onLocationChanged(Location location) {
    716 		double latitute = location.getLatitude();
    717 		double longitude = location.getLongitude();
    718 		// do whatever you want with the coordinates
    719 	}
    720 });
    721           </content>
    722        </item>
    723        <item
    724        class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
    725              description="%snippet.gps.lastCoordinates.description"
    726              id="com.motorola.studio.android.codesnippets.item4"
    727              label="%snippet.gps.lastCoordinates">
    728           <content>
    729              // To use these LocationManager methods, AndroidManifest.xml must have the following permission:
    730 // &lt;uses-permission android:name=&quot;android.permission.ACCESS_FINE_LOCATION&quot;/&gt;
    731 LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    732 Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    733 double latitute, longitude = 0;
    734 if(location != null){
    735 	latitute = location.getLatitude();
    736 	longitude = location.getLongitude();
    737 }
    738              
    739           </content>
    740        </item>
    741        <item
    742              description="%snippet.gps.distance.description"
    743              id="com.motorola.studio.android.codesnippets.item7"
    744              label="%snippet.gps.distance">
    745           <content>
    746              Location originLocation = new Location(&quot;gps&quot;);
    747 Location destinationLocation = new Location(&quot;gps&quot;);
    748 originLocation.setLatitude(originLatitude);
    749 originLocation.setLongitude(originLongitude);
    750 destinationLocation.setLatitude(originLatitude);
    751 destinationLocation.setLongitude(originLongitude);
    752 float distance = originLocation.distanceTo(destinationLocation);
    753              
    754           </content>
    755        </item>
    756        <item
    757        class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
    758              description="%snippet.gps.listenerChanges.description"
    759              id="com.motorola.studio.android.codesnippets.item1"
    760              label="%snippet.gps.listenerChanges">
    761           <content>
    762              // To use these LocationManager methods, AndroidManifest.xml must have the following permission:
    763 // &lt;uses-permission android:name=&quot;android.permission.ACCESS_FINE_LOCATION&quot;/&gt;
    764 LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    765 locationManager.addGpsStatusListener(new GpsStatus.Listener(){
    766 
    767 	public void onGpsStatusChanged(int event) {
    768 		switch(event){
    769 			// Event sent when the GPS system has started
    770 			case GpsStatus.GPS_EVENT_STARTED:
    771 				// put your code here
    772 				break;
    773 				
    774 			// Event sent when the GPS system has stopped
    775 			case GpsStatus.GPS_EVENT_STOPPED:
    776 				// put your code here
    777 				break;
    778 				
    779 			// Event sent when the GPS system has received its first fix since starting
    780 			case GpsStatus.GPS_EVENT_FIRST_FIX:
    781 				// put your code here
    782 				break;
    783 			
    784 			// Event sent periodically to report GPS satellite status
    785 			case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
    786 				// put your code here
    787 				break;
    788 		    	 
    789 		}
    790 	}
    791 });
    792           </content>
    793        </item>
    794        <item
    795        class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
    796              description="%snippet.gps.listenerProximity.description"
    797              id="com.motorola.studio.android.codesnippets.item2"
    798              label="%snippet.gps.listenerProximity">
    799           <content>
    800              // To use these LocationManager methods, AndroidManifest.xml must have the following permission:
    801 // &lt;uses-permission android:name=&quot;android.permission.ACCESS_FINE_LOCATION&quot;/&gt;
    802 // Use PendingIntent.getActivity(Context, int, Intent, int), PendingIntent.getBroadcast(Context, int, Intent, int) or PendingIntent.getService(Context, int, Intent, int) to create the PendingIntent, which will be used to generate an Intent to fire when the proximity condition is satisfied.
    803 PendingIntent pendingIntent;
    804 // latitude 	the latitude of the central point of the alert region
    805 // longitude 	the longitude of the central point of the alert region
    806 // radius 		the radius of the alert region, in meters
    807 LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    808 locationManager.addProximityAlert(latitude, longitude, radius, -1, pendingIntent);
    809           </content>
    810        </item>
    811     </category>
    812     <category
    813           description="%category.media.description"
    814           id="android_media"
    815           label="%category.media">
    816        <item
    817              description="%snippet.media.playAudioVideoRaw.description"
    818              id="com.motorola.studio.android.codesnippets.item17"
    819              label="%snippet.media.playAudioVideoRaw">
    820           <content>
    821              // Put the media file into the res/raw folder of your application
    822 MediaPlayer mp = MediaPlayer.create(this, R.raw.yourSoundId);
    823 mp.start();
    824           </content>
    825        </item>
    826        <item
    827              description="%snippet.media.playAudioVideoFile.description"
    828              id="com.motorola.studio.android.codesnippets.item18"
    829              label="%snippet.media.playAudioVideoFile">
    830           <content>
    831              MediaPlayer mp = new MediaPlayer();
    832 mp.setDataSource(FILE_PATH_OR_URL);
    833 mp.prepare();
    834 mp.start();
    835           </content>
    836        </item>
    837        <item
    838        class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
    839              description="%snippet.media.startRecordingAudio.description"
    840              id="com.motorola.studio.android.codesnippets.item16"
    841              label="%snippet.media.startRecordingAudio">
    842           <content>
    843              // To use these MediaRecorder methods, AndroidManifest.xml must have the following permission:
    844 // &lt;uses-permission android:name=&quot;android.permission.RECORD_AUDIO&quot;/&gt;
    845 MediaRecorder recorder = new MediaRecorder();
    846 recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    847 recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    848 recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    849 recorder.setOutputFile(PATH_NAME); // The file must already exist
    850 recorder.prepare();
    851 recorder.start();
    852           </content>
    853        </item>
    854        <item
    855              description="%snippet.media.stopRecording.description"
    856              id="com.motorola.studio.android.codesnippets.item21"
    857              label="%snippet.media.stopRecording">
    858           <content>
    859              recorder.stop();
    860 recorder.release();
    861           </content>
    862        </item>
    863     </category>
    864     <category
    865           description="%category.motorolaapi.description"                   
    866           id="android_motorolaapi"
    867           label="%category.motorolaapi">
    868        <item
    869              class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"           
    870              description="%snippet.motorolaapi.ffcamera.description"
    871              id="com.motorola.studio.android.codesnippets.motorolaapi1"
    872              label="%snippet.motorolaapi.ffcamera">
    873           <content>
    874              // To use these Camera methods, AndroidManifest.xml must have the following permission:
    875 // &lt;uses-permission android:name=&quot;android.permission.CAMERA&quot;/&gt;
    876 // Add an import com.motorola.hardware.frontcamera.FrontCamera; statement
    877 // Add an import android.hardware.Camera; statement
    878 // Note that you need to add a Motorola library to make this work.
    879 // See more details at: 
    880 // https://developer.motorola.com/docstools/library/motorola-front-facing-camera-api/
    881 
    882 Camera frontCam = FrontCamera.getFrontCamera();
    883 // the frontCam object represents the front-facing camera
    884 // treat it like any other Camera object
    885 frontCam.release();   // always release when done with the Camera object
    886           </content>
    887        </item>
    888        <item description="%snippet.motorolaapi.hdmi.description"
    889              id="com.motorola.studio.android.codesnippets.motorolaapi2"
    890              label="%snippet.motorolaapi.hdmi">
    891           <content>
    892 // Insert the code below into the onReceive method of a BroadcastReceiver class
    893 // This broadcast receiver must have the following intent filter:
    894 // &lt;intent-filter&gt;
    895 //     &lt;action android:name="com.motorola.intent.action.externaldisplaystate"/&gt;
    896 // &lt;/intent-filter&gt;
    897 // More details about Motorola HDMI Status API are available at: 
    898 // https://developer.motorola.com/docstools/library/motorola-hdmi-status-api/
    899 final String EXTDISP_PUBLIC_STATE = "com.motorola.intent.action.externaldisplaystate";
    900 final String EXTRA_HDCP = "";
    901 final String EXTRA_HDMI = "";
    902    
    903 String action = intent.getAction();
    904 Bundle extras = (intent != null) ? intent.getExtras() : null;
    905 
    906 if (action.equals(EXTDISP_PUBLIC_STATE))
    907 {
    908    if (extras != null)
    909    {
    910       int hdmi = extras.getInt(EXTRA_HDMI);
    911       int hdcp = extras.getInt(EXTRA_HDCP);
    912       // Application decides what to do with this information
    913    }
    914 }     
    915           </content>
    916        </item>
    917     </category>
    918     <category
    919           description="%category.preferences.description"
    920           id="com.motorola.studio.android.codesnippets.category2"
    921           label="%category.preferences">
    922        <item
    923              description="%snippet.preferences.loadSharedPreference.description"
    924              id="com.motorola.studio.android.codesnippets.item5"
    925              label="%snippet.preferences.loadSharedPreference">
    926           <content>
    927 // Use MODE_WORLD_READABLE and/or MODE_WORLD_WRITEABLE to grant access to other applications
    928 SharedPreferences preferences = getSharedPreferences(&quot;YourPreferencesName&quot;, MODE_PRIVATE);
    929 String preferenceValue = preferences.getString(&quot;yourPreferenceKey&quot;, &quot;defaultValue&quot;);
    930           </content>
    931        </item>
    932        <item
    933              description="%snippet.preferences.loadSharedPreferenceFromPreferenceManager.description"
    934              id="com.motorola.studio.android.codesnippets.item8"
    935              label="%snippet.preferences.loadSharedPreferenceFromPreferenceManager">
    936           <content>
    937 // Use MODE_WORLD_READABLE and/or MODE_WORLD_WRITEABLE to grant access to other applications
    938 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    939 String preferenceValue = preferences.getString(&quot;yourPreferenceKey&quot;, &quot;defaultValue&quot;);
    940           </content>
    941        </item>
    942        <item
    943              description="%snippet.preferences.writeSharedPreference.description"
    944              id="com.motorola.studio.android.codesnippets.item7"
    945              label="%snippet.preferences.writeSharedPreference">
    946           <content>
    947 // Use MODE_WORLD_READABLE and/or MODE_WORLD_WRITEABLE to grant access to other applications
    948 SharedPreferences preferences = getSharedPreferences(&quot;YourPreferencesName&quot;, MODE_PRIVATE);
    949 SharedPreferences.Editor editor = preferences.edit();
    950 editor.putString(&quot;yourPreferenceKey&quot;, &quot;Your Preference Value&quot;);
    951 editor.commit();
    952           </content>
    953        </item>
    954        <item
    955              description="%snippet.preferences.writeSharedPreferenceFromPreferenceManager.description"
    956              id="com.motorola.studio.android.codesnippets.item5"
    957              label="%snippet.preferences.writeSharedPreferenceFromPreferenceManager">
    958           <content>
    959 // Use MODE_WORLD_READABLE and/or MODE_WORLD_WRITEABLE to grant access to other applications
    960 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    961 SharedPreferences.Editor editor = preferences.edit();
    962 editor.putString(&quot;yourPreferenceKey&quot;, &quot;Your Preference Value&quot;);
    963 editor.commit();
    964           </content>
    965        </item>
    966     </category>
    967     <category
    968           description="%category.resources.description"
    969           id="android_resources"
    970           label="%category.resources">
    971        <item
    972              description="%snippet.resources.listAssets.description"
    973              id="com.motorola.studio.android.codesnippets.item24"
    974              label="%snippet.resources.listAssets">
    975           <content>
    976              String fileArray[] = this.getAssets().list(&quot;&quot;);
    977           </content>
    978        </item>
    979        <item
    980              description="%snippet.resources.readFile.description"
    981              id="com.motorola.studio.android.codesnippets.item22"
    982              label="%snippet.resources.readFile">
    983           <content>
    984              InputStream is = this.getAssets().open(fileName);
    985           </content>
    986        </item>
    987        <item
    988              description="%snippet.resources.readXmlFile.description"
    989              id="com.motorola.studio.android.codesnippets.item23"
    990              label="%snippet.resources.readXmlFile">
    991           <content>
    992              XmlResourceParser xmlParser = this.getAssets().openXmlResourceParser(fileName);
    993              
    994           </content>
    995        </item>
    996     </category>
    997     
    998     
    999     
   1000     <category
   1001           description="%category.log.description"
   1002           id="android_log"
   1003           label="%category.log">
   1004        <item
   1005              description="%snippet.log.error.description"
   1006              id="com.motorola.studio.android.codesnippets.item16"
   1007              label="%snippet.log.error">
   1008           <content>
   1009              Log.e(&quot;YourIdentifier&quot;,&quot;This is an error message&quot;);
   1010           </content>
   1011        </item>
   1012        <item
   1013              description="%snippet.log.warning.description"
   1014              id="com.motorola.studio.android.codesnippets.item26"
   1015              label="%snippet.log.warning">
   1016           <content>
   1017              Log.w(&quot;YourIdentifier&quot;,&quot;This is a warning message&quot;);
   1018           </content>
   1019        </item>
   1020        <item
   1021              description="%snippet.log.info.description"
   1022              id="com.motorola.studio.android.codesnippets.item27"
   1023              label="%snippet.log.info">
   1024           <content>
   1025              Log.i(&quot;YourIdentifier&quot;,&quot;This is an information message&quot;);
   1026           </content>
   1027        </item>
   1028        <item
   1029              description="%snippet.log.debug.description"
   1030              id="com.motorola.studio.android.codesnippets.item28"
   1031              label="%snippet.log.debug">
   1032           <content>
   1033              Log.d(&quot;YourIdentifier&quot;,&quot;This is a debug message&quot;);
   1034           </content>
   1035        </item>
   1036     </category>
   1037     <category
   1038           description="%category.localization.description"
   1039           id="android_localization"
   1040           label="%category.localization">
   1041        <item
   1042              description="%snippet.localization.string.description"
   1043              id="com.motorola.studio.android.codesnippets.item1"
   1044              label="%snippet.localization.string">
   1045           <content>
   1046              String text = getResources().getString(R.string.yourStringID);
   1047           </content>
   1048        </item>
   1049        <item
   1050              description="%snippet.localization.drawable.description"
   1051              id="com.motorola.studio.android.codesnippets.item2"
   1052              label="%snippet.localization.drawable">
   1053           <content>
   1054              Drawable drawable = getResources().getDrawable(R.drawable.yourDrawableID);
   1055           </content>
   1056        </item>
   1057        <item
   1058              description="%snippet.localization.curLocale.description"
   1059              id="com.motorola.studio.android.codesnippets.item4"
   1060              label="%snippet.localization.curLocale">
   1061           <content>
   1062              Locale curLocale = java.util.Locale.getDefault();
   1063           </content>
   1064        </item>
   1065        <item
   1066              description="%snippet.localization.resLocale.description"
   1067              id="com.motorola.studio.android.codesnippets.item5"
   1068              label="%snippet.localization.resLocale">
   1069           <content>
   1070              Locale resLocale = getResources().getConfiguration().locale;
   1071           </content>
   1072        </item>
   1073        <item
   1074              description="%snippet.localization.dynamicMsg.description"
   1075              id="com.motorola.studio.android.codesnippets.item3"
   1076              label="%snippet.localization.dynamicMsg">
   1077           <content>
   1078              // yourMsgID =&quot;The language is {0}&quot;
   1079 String msg = getResources().getString(R.string.yourMsgID); 
   1080 Object[] arguments = {
   1081         	java.util.Locale.getDefault().getDisplayLanguage()
   1082 };
   1083 String fullMsg = java.text.MessageFormat.format(msg, arguments);
   1084           </content>
   1085        </item>
   1086     </category>
   1087     <category
   1088           description="%category.bluetooth.description"
   1089           id="android_bluetooth"
   1090           label="%category.bluetooth">
   1091        <item
   1092              class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
   1093              description="%snippet.bluetooth.check.description"
   1094              id="com.motorola.studio.android.codesnippets.bt1"
   1095              label="%snippet.bluetooth.check">
   1096           <content>
   1097              // To use this BluetoothAdapter method, AndroidManifest.xml must have the following permission:
   1098 //&lt;uses-permission android:name=&quot;android.permission.BLUETOOTH&quot;/&gt;
   1099 // Trying to get the adapter
   1100 BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
   1101 
   1102 if (btAdapter == null) {
   1103       // Bluetooth is not supported, do something here to warn the user
   1104       return;
   1105 }
   1106           </content>
   1107        </item>
   1108        <item
   1109              class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
   1110              description="%snippet.bluetooth.connect.description"
   1111              id="com.motorola.studio.android.codesnippets.bt7"
   1112              label="%snippet.bluetooth.connect">
   1113           <content>
   1114              // To use these BluetoothAdapter methods, AndroidManifest.xml must have the following permission:
   1115 //&lt;uses-permission android:name=&quot;android.permission.BLUETOOTH&quot;/&gt;
   1116 /*
   1117  * This code is loose here but you will
   1118  * likely use it inside a thread
   1119  * 
   1120  * Make sure you have the &apos;device&apos; variable (BluetoothDevice)
   1121  * at the point you insert this code
   1122  */
   1123 
   1124 // UUID for your application
   1125 UUID MY_UUID = UUID.fromString(&quot;yourdata&quot;);     
   1126 
   1127 // Get the adapter
   1128 BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
   1129 
   1130 // The socket
   1131 BluetoothSocket socket = null;
   1132 try {
   1133     // Your app UUID string (is also used by the server) 
   1134     socket = device.createRfcommSocketToServiceRecord(MY_UUID); 	
   1135 } catch (IOException e) { }
   1136 
   1137 // For performance reasons
   1138 btAdapter.cancelDiscovery();
   1139 
   1140 try {
   1141     // Be aware that this is a blocking operation. You probably want to use this in a thread
   1142     socket.connect();
   1143     
   1144 } catch (IOException connectException) {
   1145     // Unable to connect; close the socket and get out
   1146     try {
   1147     	socket.close();
   1148     } catch (IOException closeException) {
   1149     	// Deal with it
   1150     }
   1151     return;
   1152 }
   1153 
   1154 // Now manage your connection (in a separate thread)
   1155 myConnectionManager(socket);
   1156           </content>
   1157        </item>
   1158        <item
   1159              class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
   1160              description="%snippet.bluetooth.enable.description"
   1161              id="com.motorola.studio.android.codesnippets.bt2"
   1162              label="%snippet.bluetooth.enable">
   1163           <content>
   1164              // To use these BluetoothAdapter methods, AndroidManifest.xml must have the following permission:
   1165 //&lt;uses-permission android:name=&quot;android.permission.BLUETOOTH&quot;/&gt;
   1166 /* This number is used to identify this request (&quot;Enable Bluetooth&quot;) 
   1167  * when the callback method onActivityResult() is called. Your
   1168  * interaction with the Bluetooth stack will probably start there. 
   1169  * 
   1170  * You probably want to insert this as a global variable 
   1171  */
   1172 int ENABLE_BLUETOOTH = 1;
   1173     
   1174 // Get the adapter
   1175 BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
   1176 
   1177 if (btAdapter == null) {	
   1178     return;
   1179 }
   1180   	
   1181 // If Bluetooth is not yet enabled, enable it    
   1182 if (!btAdapter.isEnabled()) {
   1183     Intent enableBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
   1184     startActivityForResult(enableBluetooth, ENABLE_BLUETOOTH);
   1185     // Now implement the onActivityResult() and wait for it to be invoked with ENABLE_BLUETOOTH 
   1186 }
   1187           </content>
   1188        </item>
   1189        <item
   1190              class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
   1191              description="%snippet.bluetooth.getpaired.description"
   1192              id="com.motorola.studio.android.codesnippets.bt4"
   1193              label="%snippet.bluetooth.getpaired">
   1194           <content>
   1195              // To use these BluetoothAdapter methods, AndroidManifest.xml must have the following permission:
   1196 //&lt;uses-permission android:name=&quot;android.permission.BLUETOOTH&quot;/&gt;
   1197 // Get the adapter
   1198 BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
   1199 
   1200 // Get the paired devices
   1201 Set&lt;BluetoothDevice&gt; devices = btAdapter.getBondedDevices();
   1202 
   1203 // If there are paired devices, do whatever you&apos;re supposed to do
   1204 if (devices.size() &gt; 0) {
   1205     for (BluetoothDevice pairedDevice : devices) {
   1206         // do something useful with the device
   1207     }
   1208 }
   1209           </content>
   1210        </item>
   1211        <item
   1212              class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
   1213              description="%snippet.bluetooth.discoverable.description"
   1214              id="com.motorola.studio.android.codesnippets.bt3"
   1215              label="%snippet.bluetooth.discoverable">
   1216           <content>
   1217              // To use these BluetoothAdapter methods, AndroidManifest.xml must have the following permission:
   1218 //&lt;uses-permission android:name=&quot;android.permission.BLUETOOTH&quot;/&gt;
   1219 //Get the adapter	
   1220 BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
   1221 
   1222 if (btAdapter == null) {	
   1223     return;
   1224 }
   1225 
   1226 // If Bluetooth is not discoverable, make it discoverable
   1227 if (btAdapter.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {	
   1228 	Intent makeDiscoverable = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
   1229     makeDiscoverable.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 500);
   1230 	// In a real situation you would probably use startActivityForResult to get the user&apos;s choice.
   1231     startActivity(makeDiscoverable);
   1232 }
   1233           </content>
   1234        </item>
   1235        <item
   1236              class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
   1237              description="%snippet.bluetooth.incoming.description"
   1238              id="com.motorola.studio.android.codesnippets.bt6"
   1239              label="%snippet.bluetooth.incoming">
   1240           <content>
   1241              // To use these BluetoothAdapter methods, AndroidManifest.xml must have the following permission:
   1242 //&lt;uses-permission android:name=&quot;android.permission.BLUETOOTH&quot;/&gt;
   1243 // UUID for your application
   1244 UUID MY_UUID = UUID.fromString(&quot;yourdata&quot;);        
   1245 
   1246 // SDP record name used when creating the server socket
   1247 String NAME = &quot;BluetoothExample&quot;;
   1248 
   1249 // The server socket
   1250 BluetoothServerSocket btServerSocket =  null;
   1251 
   1252 // The adapter
   1253 BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
   1254 
   1255 // The socket
   1256 BluetoothSocket socket = null;
   1257 
   1258 try {
   1259 	btServerSocket = btAdapter.listenUsingRfcommWithServiceRecord(NAME, MY_UUID);
   1260 
   1261 	// This operation is blocking: you will wait until it returns or an error occurs
   1262     socket = btServerSocket.accept();	
   1263 } catch (IOException e) {
   1264 	// Deal with it
   1265 }
   1266 
   1267 if (socket != null) {
   1268 	/* The connection was accepted. Do what you want to do.
   1269 	* For example, get the streams        	       	
   1270 	*/
   1271     InputStream inputStream = null;
   1272     OutputStream outputStream = null;
   1273     try {
   1274         inputStream = socket.getInputStream();
   1275         outputStream = socket.getOutputStream();
   1276     } catch (IOException e) {
   1277         // Deal with it
   1278     }                       
   1279 }
   1280           </content>
   1281        </item>
   1282        <item
   1283              class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
   1284              description="%snippet.bluetooth.discover.description"
   1285              id="com.motorola.studio.android.codesnippets.bt5"
   1286              label="%snippet.bluetooth.discover">
   1287           <content>
   1288              // To use these BluetoothDevice methods, AndroidManifest.xml must have the following permission:
   1289 //&lt;uses-permission android:name=&quot;android.permission.BLUETOOTH&quot;/&gt;
   1290 
   1291 // BroadcastReceiver that is notified as each device is found and when the discovery process completes 
   1292 // Should be an internal class or in a separate .java file
   1293 final BroadcastReceiver bluetoothReceiver = new BroadcastReceiver() {
   1294     @Override
   1295     public void onReceive(Context context, Intent intent) {
   1296         String action = intent.getAction();
   1297 
   1298         // Device was discovered
   1299         if (BluetoothDevice.ACTION_FOUND.equals(action)) {
   1300             BluetoothDevice device = 
   1301 intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
   1302             if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
   1303                 // device is not already paired. Do something useful here.
   1304             }
   1305         // Discovery is finished
   1306         } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
   1307         	// do something useful here                
   1308         }
   1309     }
   1310 };
   1311 
   1312 // Register for notification upon discovery of a Bluetooth device
   1313 IntentFilter intentFilter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
   1314 this.registerReceiver(bluetoothReceiver, intentFilter);
   1315 
   1316 // Register for notification upon completion of the device discovery process 
   1317 intentFilter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
   1318 this.registerReceiver(bluetoothReceiver, intentFilter);
   1319 
   1320           </content>
   1321        </item>
   1322     </category>
   1323     <category
   1324           description="%category.sql.description"
   1325           id="android_sql"
   1326           label="%category.sql">
   1327        <item
   1328              description="%snippet.sql.create.description"
   1329              id="com.motorola.studio.android.codesnippets.sql1"
   1330              label="%snippet.sql.create">
   1331           <content>
   1332              CREATE TABLE songs(
   1333     id  INTEGER,
   1334     name  TEXT,         
   1335     genre  TEXT, 
   1336     rate  REAL,     
   1337     some_raw_data BLOB      
   1338 );
   1339           </content>
   1340        </item>
   1341        <item
   1342              description="%snippet.sql.createfromtable.description"
   1343              id="com.motorola.studio.android.codesnippets.sql2"
   1344              label="%snippet.sql.createfromtable">
   1345           <content>
   1346              SELECT *  INTO rockssongs
   1347 FROM songs WHERE genre =&apos;rock&apos;;
   1348           </content>
   1349        </item>
   1350        <item
   1351              description="%snippet.sql.count.description"
   1352              id="com.motorola.studio.android.codesnippets.sql3"
   1353              label="%snippet.sql.count">
   1354           <content>
   1355              SELECT COUNT(DISTINCT student_city) AS total
   1356 FROM students;
   1357           </content>
   1358        </item>
   1359        <item
   1360              description="%snippet.sql.delete.description"
   1361              id="com.motorola.studio.android.codesnippets.sql4"
   1362              label="%snippet.sql.delete">
   1363           <content>
   1364 DELETE FROM songs
   1365 WHERE rating&lt; 5;
   1366           </content>
   1367        </item>
   1368        <item
   1369              description="%snippet.sql.drop.description"
   1370              id="com.motorola.studio.android.codesnippets.sql5"
   1371              label="%snippet.sql.drop">
   1372           <content>
   1373              DROP TABLE&quot;bad_songs&quot;;
   1374           </content>
   1375        </item>
   1376        <item
   1377              description="%snippet.sql.left.description"
   1378              id="com.motorola.studio.android.codesnippets.sql6"
   1379              label="%snippet.sql.left">
   1380           <content>
   1381              SELECT students.name 
   1382 FROM students LEFT JOIN math_class
   1383     ON students.id = math_class.student_id 
   1384 WHERE math_class.grade &gt; 5;
   1385           </content>
   1386        </item>
   1387        <item
   1388              description="%snippet.sql.inner.description"
   1389              id="com.motorola.studio.android.codesnippets.sql7"
   1390              label="%snippet.sql.inner">
   1391           <content>
   1392              SELECT DISTINCT students.id, students.name
   1393 FROM students INNER JOIN math_class ON students.id = math_class.student_id;
   1394           </content>
   1395        </item>
   1396        <item
   1397              description="%snippet.sql.insert.description"
   1398              id="com.motorola.studio.android.codesnippets.sql8"
   1399              label="%snippet.sql.insert">
   1400           <content>
   1401              INSERT INTO albums(ambum_id, artist_name, album_name)
   1402 VALUES(&apos;12345&apos;, &apos;David Bowie&apos;,&apos;Ziggy Stardust&apos;);
   1403           </content>
   1404        </item>
   1405        <item
   1406              description="%snippet.sql.update.description"
   1407              id="com.motorola.studio.android.codesnippets.sql9"
   1408              label="%snippet.sql.update">
   1409           <content>
   1410              UPDATE songs SET already_listened =&quot;yes&quot;
   1411 WHERE genre = &quot;rock&quot;;
   1412           </content>
   1413        </item>
   1414     </category>
   1415     <category
   1416           description="%category.web.description"
   1417           id="android_web"
   1418           label="%category.web">
   1419        <item
   1420              class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
   1421              description="%snippet.web.get.description"
   1422              id="com.motorola.studio.android.codesnippets.web1"
   1423              label="%snippet.web.get">
   1424           <content>
   1425              // To use these Internet methods, AndroidManifest.xml must have the following permission:
   1426 //&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;/&gt;
   1427 URI myURI = null;
   1428 try {
   1429 	myURI = new URI(&quot;www.webserver.org&quot;);
   1430 } catch (URISyntaxException e) {
   1431 	// Deal with it
   1432 }
   1433 HttpClient httpClient = new DefaultHttpClient();
   1434 HttpGet getMethod = new HttpGet(myURI);
   1435 HttpResponse webServerResponse = null;
   1436 try {
   1437 	webServerResponse = httpClient.execute(getMethod);
   1438 } catch (ClientProtocolException e) {
   1439 	// Deal with it
   1440 } catch (IOException e) {
   1441 	// Deal with it
   1442 }
   1443 
   1444 HttpEntity httpEntity = webServerResponse.getEntity();
   1445 
   1446 if (httpEntity != null) {
   1447 	// You have your response; handle it. For instance, with an input
   1448 	// stream
   1449 	// InputStream input = entity.getContent();
   1450 }
   1451           </content>
   1452        </item>
   1453        <item
   1454              class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
   1455              description="%snippet.web.post.description"
   1456              id="com.motorola.studio.android.codesnippets.web2"
   1457              label="%snippet.web.post">
   1458           <content>
   1459              // To use these Internet methods, AndroidManifest.xml must have the following permission:
   1460 //&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;/&gt;
   1461 // Create the Apache HTTP client and post  
   1462  HttpClient httpclient = new DefaultHttpClient();
   1463  HttpPost httppost = new HttpPost(&quot;http://www.website.org/service.php";);  
   1464    
   1465      try {  
   1466          // Add data to your post  
   1467      List&lt;NameValuePair&gt; pairs = new ArrayList&lt;NameValuePair&gt;(2);  
   1468      pairs.add(new BasicNameValuePair(&quot;ID&quot;, &quot;VALUE&quot;));  
   1469      pairs.add(new BasicNameValuePair(&quot;string&quot;, &quot;Yeah!&quot;));  
   1470      httppost.setEntity(new UrlEncodedFormEntity(pairs));  
   1471    
   1472      //Finally, execute the request  
   1473      HttpResponse webServerAnswer = httpclient.execute(httppost);  
   1474        
   1475  } catch (ClientProtocolException e) {  
   1476      //Deal with it  
   1477  } catch (IOException e) {  
   1478      //Deal with it  
   1479  }
   1480           </content>
   1481        </item>
   1482        <item
   1483              class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
   1484              description="%snippet.web.json.description"
   1485              id="com.motorola.studio.android.codesnippets.web3"
   1486              label="%snippet.web.json">
   1487           <content>
   1488              // To use these Internet methods, AndroidManifest.xml must have the following permission:
   1489 //&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;/&gt;
   1490 // The JSON objects
   1491 JSONObject myJSON = null;
   1492 JSONArray names = null;
   1493 JSONArray values = null;
   1494   
   1495 String restWebServerResponse = &quot;TheResponse&quot;;
   1496 try{  
   1497         myJSON = new JSONObject(restWebServerResponse);  
   1498         names = myJSON.names();  
   1499         values = myJSON.toJSONArray(names);    
   1500 }  
   1501 catch (JSONException e) {  
   1502         // Deal with it  
   1503 }        
   1504   	         
   1505 for (int i = 0; i &lt; values.length(); i++) {	   	 	   	 
   1506   // Do something with values.getString(i)
   1507 }
   1508           </content>
   1509        </item>
   1510        <item
   1511              class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
   1512              description="%snippet.web.rest.description"
   1513              id="com.motorola.studio.android.codesnippets.web4"
   1514              label="%snippet.web.rest">
   1515           <content>
   1516              // To use these Internet methods, AndroidManifest.xml must have the following permission:
   1517 //&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;/&gt;
   1518 // This assumes that you have a URL from which to get the answer
   1519 URI myURL = new URI(&quot;www.website.org&quot;);
   1520 
   1521 // The HTTP objects
   1522 HttpClient httpClient = new DefaultHttpClient();
   1523 HttpGet getMethod = new HttpGet(myURL);
   1524 HttpResponse httpResponse;
   1525 
   1526 // The query result
   1527 String result = null;
   1528 
   1529 try {
   1530 	httpResponse = httpClient.execute(getMethod);
   1531 	// You might want to check response.getStatusLine().toString()
   1532 
   1533 	HttpEntity entity = httpResponse.getEntity();
   1534 
   1535 	if (entity != null) {
   1536 		InputStream instream = entity.getContent();
   1537 		BufferedReader reader = new BufferedReader( new InputStreamReader(instream));
   1538 		StringBuilder sb = new StringBuilder();
   1539 		String line = null;
   1540 	try {
   1541 		while ((line = reader.readLine()) != null) {
   1542 			sb.append(line + &quot;\n&quot;);
   1543 		}
   1544 	} catch (IOException e) {
   1545 	// Deal with it
   1546 	} finally {
   1547 		try {
   1548 			instream.close();
   1549 		} catch (IOException e) {
   1550 		// Deal with it
   1551 		}
   1552 	}
   1553 	
   1554 	// Handle the result (for instance, get a JSON object
   1555 	// using the &quot;Retrieve JSON from a server response&quot; snippet)
   1556 	handleResult(result);
   1557 	}
   1558 } catch (ClientProtocolException e) {
   1559 	// Deal with it
   1560 } catch (IOException e) {
   1561 	// Deal with it
   1562 }
   1563           </content>
   1564        </item>
   1565        <item
   1566        class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
   1567              description="%snippet.web.email.description"
   1568              id="com.motorola.studio.android.codesnippets.web5"
   1569              label="%snippet.web.email">
   1570           <content>
   1571              // To use these Internet methods, AndroidManifest.xml must have the following permission:
   1572 // &lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;/&gt;
   1573 Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
   1574 emailIntent.setType(&quot;plain/text&quot;);  
   1575 emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{&quot;to (a] email.com&quot;});  
   1576 emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, &quot;Hello!&quot;);  
   1577 emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, &quot;Hello!&quot;);  
   1578 
   1579 startActivity(Intent.createChooser(emailIntent, &quot;Send mail...&quot;));
   1580           </content>
   1581        </item>
   1582        <item
   1583              class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
   1584              description="%snippet.web.urlconnection.description"
   1585              id="com.motorola.studio.android.codesnippets.web6"
   1586              label="%snippet.web.urlconnection">
   1587           <content>
   1588              // To use these Internet methods, AndroidManifest.xml must have the following permission:
   1589 //&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;/&gt;
   1590 // The data that is retrieved 
   1591 String result = null;
   1592 
   1593 try {
   1594      // This assumes that you have a URL from which the response will come
   1595      URL url = new URL(&quot;www.webaddress.org&quot;);
   1596      
   1597      // Open a connection to the URL and obtain a buffered input stream
   1598      URLConnection connection = url.openConnection();
   1599      InputStream inputStream = connection.getInputStream();
   1600      BufferedInputStream bufferedInput = new BufferedInputStream(inputStream);
   1601      
   1602      // Read the response into a byte array
   1603      ByteArrayBuffer byteArray = new ByteArrayBuffer(50);
   1604      int current = 0;
   1605      while((current = bufferedInput.read()) != -1){
   1606           byteArray.append((byte)current);
   1607      }
   1608 
   1609      // Construct a String object from the byte array containing the response
   1610      result = new String(byteArray.toByteArray());
   1611 } catch (Exception e) {
   1612 	
   1613 }
   1614 
   1615 // Handle the result
   1616 handleResult(result);
   1617           </content>
   1618        </item>
   1619        <item
   1620              class="com.motorola.studio.android.codesnippets.AndroidPermissionInsertSnippet"
   1621              description="%snippet.web.soap.description"
   1622              id="com.motorola.studio.android.codesnippets.web7"
   1623              label="%snippet.web.soap">
   1624           <content>
   1625              // To use these Internet methods, AndroidManifest.xml must have the following permission:
   1626 //&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;/&gt;
   1627 /* This example is intended to be used with the kSOAP 
   1628  * project (http://ksoap2.sourceforge.net/), which
   1629  * provides some objects to deal with SOAP within 
   1630  * mobile development.
   1631  * 
   1632  * You must download the kSOAP objects and 
   1633  * have something like this in your import list:
   1634  * import org.ksoap2.SoapEnvelope; // (and other necessary classes)
   1635  */
   1636 String SOAP_ACTION = &quot;yourMethod&quot;;
   1637 String METHOD_NAME = &quot;yourMethod&quot;;
   1638 String NAMESPACE = &quot;http://namespace.com/";;
   1639 String URL = &quot;http://server.org";;
   1640 
   1641 SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
   1642 request.addProperty(&quot;property1&quot;, &quot;property&quot;);
   1643  
   1644 SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
   1645 envelope.setOutputSoapObject(request);
   1646 HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
   1647 androidHttpTransport.call(SOAP_ACTION, envelope);
   1648  
   1649 Object results = envelope.getResponse();
   1650  
   1651 // Handle the results
   1652 handleResults(results);
   1653           </content>
   1654        </item>
   1655     </category>
   1656     <category
   1657           description="%category.sensors.description"
   1658           id="android_sensor"
   1659           label="%category.sensors">
   1660        <item
   1661              description="%snnipet.sensor.detect.description"
   1662              id="com.motorola.studio.android.codesnippets.sensor1"
   1663              label="%snnipet.sensor.detect">
   1664           <content>
   1665              // This code requires API level 3 (Android 1.5) or higher
   1666 SensorManager manager = (SensorManager) getSystemService(SENSOR_SERVICE);
   1667 boolean isAccelerometerSupported = true;
   1668 if(manager.getSensorList(Sensor.TYPE_ACCELEROMETER).isEmpty()){
   1669      isAccelerometerSupported = false;
   1670 }
   1671           </content>
   1672        </item>
   1673        <item
   1674              description="%snnipet.sensor.getorientation.description"
   1675              id="com.motorola.studio.android.codesnippets.sensor2"
   1676              label="%snnipet.sensor.getorientation">
   1677           <content>
   1678              // This code requires API level 3 (Android 1.5) or higher
   1679 SensorManager manager;
   1680 manager = (SensorManager) getSystemService(SENSOR_SERVICE);
   1681 manager.registerListener(new SensorEventListener(){
   1682             				public void onAccuracyChanged(Sensor sensor, int accuracy){
   1683 			            	}
   1684 
   1685 			            	public void onSensorChanged(SensorEvent event){
   1686 			                  if(event.sensor.getType() == Sensor.TYPE_ORIENTATION){
   1687 			                       // The contents of the values[] array depends upon the sensor type.
   1688 			                       // See the description of the values[] array in the SensorEvent object documentation.
   1689 			                       float azimuth = Math.round(event.values[0]);
   1690 			                       float pitch = Math.round(event.values[1]);
   1691 			                       float roll = Math.round(event.values[2]);	        	     
   1692 		                       
   1693 			                       // Do something with the device orientation values
   1694 		                  	  }
   1695 		             		}},
   1696 		             		manager.getDefaultSensor(Sensor.TYPE_ORIENTATION), 
   1697 			                SensorManager.SENSOR_DELAY_NORMAL);
   1698           </content>
   1699        </item>
   1700     </category>
   1701    
   1702     <category
   1703           description="%category.ui.description"
   1704           id="ui"
   1705           label="%category.ui">
   1706        <item
   1707              description="%snippet.ui.gestures.description"
   1708              id="com.motorola.studio.android.codesnippets.ui1"
   1709              label="%snippet.ui.gestures.string">
   1710           <content>
   1711 private static final float DISTANCE_DIP = 16.0f;
   1712 private static final float PATH_DIP = 40.0f;
   1713 // convert dip measurements to pixels
   1714 final float scale = getResources().getDisplayMetrics().density;
   1715 int scaledDistance = (int) (DISTANCE_DIP * scale + 0.5f);
   1716 int scaledPath = (int) (PATH_DIP * scale + 0.5f);
   1717 // For more information about touch gestures and screens support, see:
   1718 // http://developer.android.com/resources/articles/gestures.html
   1719 // http://developer.android.com/reference/android/gesture/package-summary.html
   1720 // http://developer.android.com/guide/practices/screens_support.html
   1721           </content>
   1722        </item>
   1723        <item
   1724              description="%snippet.ui.background.description"
   1725              id="com.motorola.studio.android.codesnippets.ui3"
   1726              label="%snippet.ui.background.string">
   1727           <content>
   1728              originalImage = Bitmap.createScaledBitmap( 
   1729 originalImage,     // bitmap to resize 
   1730 view.getWidth(),   // new width 
   1731 view.getHeight(),  // new height 
   1732 true);             // bilinear filtering
   1733             
   1734           </content>
   1735        </item>
   1736        <item
   1737              description="%snippet.ui.sizes.description"
   1738              id="com.motorola.studio.android.codesnippets.ui2"
   1739              label="%snippet.ui.sizes.string">
   1740           <content>
   1741              public void onSizeChanged(int w, int h, int oldW,
   1742 int oldH) {
   1743 // Calculate relative sizes at runtime
   1744 // mButton and mButtonBackGround are of type Drawable
   1745 int selfW = mButton.getIntrinsicWidth();
   1746 int selfH = mButton.getIntrinsicHeight();
   1747 int marginX = (w - selfW) / 2;
   1748 int marginY = (h - selfH) / 2;
   1749 mButtonBackground.setBounds(marginX, marginY, 
   1750 marginX + selfW, marginY + selfH);
   1751 mButton.setBounds(marginX, marginY, 
   1752 marginX + selfW, marginY + selfH);
   1753 // Implement the measureText method to resize text data, if applicable
   1754 measureText();
   1755 }
   1756           </content>
   1757        </item>
   1758        <item
   1759              description="%snippet.ui.widget.description"
   1760              id="com.motorola.studio.android.codesnippets.ui4"
   1761              label="%snippet.ui.widget.string">
   1762           <content>
   1763           // Add import android.view.View.OnClickListener; statement
   1764 // Add import android.widget.Button; statement
   1765 // Add import android.view.View; statement
   1766          
   1767 Button b1 = (Button) findViewById(R.id.your_button_id); // Use this method carefully, it consumes lots of system resources
   1768 b1.setOnClickListener(new OnClickListener() {			
   1769 	public void onClick(View v) {
   1770 		// Handle the button click here as you wish				
   1771 	}
   1772 });
   1773           </content>
   1774        </item>
   1775        <item
   1776              description="%snippet.ui.moveout.description"
   1777              id="com.motorola.studio.android.codesnippets.ui5"
   1778              label="%snippet.ui.moveout.string">
   1779           <content>
   1780 // You must provide types for the three generic parameters before the code will compile.          
   1781 // For more details, see http://developer.android.com/reference/android/os/AsyncTask.html 
   1782  private class MoveOutOfUIthread extends AsyncTask&lt;
   1783                 Params, // one or more values of this type are passed to doInBackground()
   1784                 Progress, // the type of the progress units published during background crunching.
   1785                 Result // the type of the result returned by doInBackground()
   1786                 &gt; 
   1787  {
   1788 
   1789          protected Integer doInBackground(Params... p1, p2, p3) {
   1790              // your background task here
   1791              Result result = new Result();
   1792              return result;
   1793          }
   1794         
   1795          protected void onPostExecute(Result r) {
   1796              // this gets the object returned by doInBackground, and executes on the UI thread
   1797          }
   1798  }   
   1799  new MoveOutOfUIthread().execute(p1, p2, p3);
   1800           </content>
   1801        </item>
   1802        <item
   1803              description="%snippet.ui.backgroundtaskwithnotification.description"
   1804              id="com.motorola.studio.android.codesnippets.ui6"
   1805              label="%snippet.ui.backgroundtaskwithnotification.string">
   1806           <content>
   1807              // This code is supposed to be used as an inner class and will start a
   1808 	// background task while it notifies the user via the status bar. The outer class
   1809 	// must implement Context (sub)classes like Activity and Service. Use
   1810 	// new BackgroundTaskWithStatusBarNotification(id, title, text,
   1811 	// context).execute() to start the background task.
   1812 	private class BackgroundTaskWithStatusBarNotification extends
   1813 			AsyncTask&lt;Void, Integer, Void&gt; {
   1814 
   1815 		// A unique identifier for the notification.
   1816 		private int mId;
   1817 
   1818 		// The text that will be displayed when the status bar is expanded.
   1819 		private String mShortDesc;
   1820 
   1821 		// The text that flows by in the status bar when the notification first
   1822 		// activates.
   1823 		private String mContent;
   1824 
   1825 		// The application context where the task was launched.
   1826 		private Context mContext;
   1827 
   1828 		// The notification itself.
   1829 		private Notification mNotification;
   1830 
   1831 		// The notification manager retrieved from the system.
   1832 		private NotificationManager mNotificationManager;
   1833 
   1834 		// An intent that will be launched when user clicks the
   1835 		// notification
   1836 		PendingIntent mPendingIntent;
   1837 
   1838 		public BackgroundTaskWithStatusBarNotification(int id,
   1839 				String shortDesc, String content, Context context) {
   1840 			mId = id;
   1841 			mShortDesc = shortDesc;
   1842 			mContent = content;
   1843 			mContext = context;
   1844 		}
   1845 
   1846 		protected void onPreExecute() {
   1847 			mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
   1848 
   1849 			mNotification = new Notification(
   1850 					android.R.drawable.stat_sys_download, mContent,
   1851 					System.currentTimeMillis());
   1852 
   1853 			// TODO: enter the initial text for your task here, such as:
   1854 			// &quot;0% complete&quot;.
   1855 			String progressText = &quot;your_text_here&quot;;
   1856 
   1857 			// this intent will be launched when user clicks the notification in the
   1858 			// status bar and will start activity YourActivity
   1859 			Intent intent = new Intent(mContext, YourActivity.class);
   1860 			mPendingIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
   1861 
   1862 			// updates the notification
   1863 			mNotification.setLatestEventInfo(mContext, mShortDesc,
   1864 					progressText, mPendingIntent);
   1865 			mNotification.flags = Notification.FLAG_ONGOING_EVENT;
   1866 			mNotificationManager.notify(mId, mNotification);
   1867 		}
   1868 
   1869 		@Override
   1870 		protected Void doInBackground(Void... argList) {
   1871 
   1872 			// TODO: add the content of your background task here. Call
   1873 			// AsyncTask.publishProgress() method to update the  
   1874 			// tasks progress (method onProgressUpdate() will handle this
   1875 			// progress update).
   1876 
   1877 			return null;
   1878 		}
   1879 
   1880 		protected void onProgressUpdate(Integer... progress) {
   1881 
   1882 			// TODO: supply the text that must be displayed while the task is in
   1883 			// progress. For instance, &quot;progress[0] + &quot;% complete&quot;.
   1884 			String contentText = &quot;your_text_here&quot;;
   1885 
   1886 			// updates the notification
   1887 			mNotification.setLatestEventInfo(mContext, mShortDesc, contentText,
   1888 					mPendingIntent);
   1889 			mNotificationManager.notify(mId, mNotification);
   1890 		}
   1891 
   1892 		protected void onPostExecute(Void result) {
   1893 			// TODO: supply the final text that must be displayed when the task
   1894 			// is done. For instance, &quot;Done&quot;.
   1895 			String contentText = &quot;your_text_here&quot;;
   1896 
   1897 			// updates the notification
   1898 			mNotification.icon = android.R.drawable.stat_sys_download_done;
   1899 			mNotification.setLatestEventInfo(mContext, mShortDesc, contentText,
   1900 					mPendingIntent);
   1901 			mNotificationManager.notify(mId, mNotification);
   1902 		}
   1903 }
   1904           </content>
   1905        </item>
   1906        <item
   1907              description="%snippet.ui.hide.statusbar.description"
   1908              id="com.motorola.studio.android.codesnippets.item6"
   1909              label="%snippet.ui.hide.statusbar.label">
   1910           <content>
   1911              //Hides status bar (if it was showing)
   1912 View v = findViewById(R.id.view_id); //for example, the ID representing the root of a linear layout
   1913 v.setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
   1914           </content>
   1915        </item>
   1916        <item
   1917              description="%snippet.ui.visible.statusbar.description"
   1918              id="com.motorola.studio.android.codesnippets.item7"
   1919              label="%snippet.ui.visible.statusbar.label">
   1920           <content>
   1921              //Shows status bar (if it was hidden)
   1922 View v = findViewById(R.id.view_id); //for example, the ID representing the root of a linear layout
   1923 v.setSystemUiVisibility(View.STATUS_BAR_VISIBLE);
   1924           </content>
   1925        </item>
   1926     </category>  
   1927     <category
   1928           description="%intents.ui.description"
   1929           id="android_intents"
   1930           label="%intents.ui">
   1931        <item
   1932              description="%intents.start.activity.explicitly.description"
   1933              id="com.motorola.studio.android.codesnippets.intents1"
   1934              label="%intents.start.activity.explicitly.label">
   1935           <content>
   1936              //Calls another activity, by name, without passing data
   1937 
   1938 Intent iExp = new Intent(this, ActivityToCall.class); //TODO  Replace 'ActivityToCall' with the class name of the activity being called
   1939 
   1940 startActivity(iExp);
   1941           </content>
   1942        </item>
   1943        <item
   1944              description="%intents.start.activity.implicitly.description"
   1945              id="com.motorola.studio.android.codesnippets.item2"
   1946              label="%intents.start.activity.implicitly.label">
   1947           <content>
   1948              //Calls another activity, by action and category, without passing data
   1949 //refer to AndroidManifest.xml&lt;intent-filter&gt; when determining the action and category of the activity to call
   1950 Intent iImp = new Intent(&quot;actionName&quot;); //TODO Replace 'actionName' as appropriate for your action (for example, Intent.ACTION_EDIT)
   1951 iImp.addCategory(&quot;categoryName&quot;); //TODO Replace 'categoryName' as appropriate for your category (for example, Intent.CATEGORY_DEFAULT)
   1952 startActivity(iImp);
   1953           </content>
   1954        </item>
   1955        <item
   1956              description="%intents.start.activity.for.result.description"
   1957              id="com.motorola.studio.android.codesnippets.item3"
   1958              label="%intents.start.activity.for.result.label">
   1959           <content>
   1960              //Calls another activity, identified by action and category, passing data URL and a MIME type
   1961 //The class calling the snippet code must implement the following method:
   1962 //protected void onActivityResult (int requestCode, int resultCode, Intent data) {}
   1963 Intent iImp = new Intent();
   1964 iImp.setAction(&quot;actionName&quot;); //TODO Replace 'actionName' as appropriate for your action (for example, Intent.ACTION_EDIT)
   1965 iImp.addCategory(&quot;categoryName&quot;); //TODO Replace 'categoryName' as appropriate for your category (for example, Intent.CATEGORY_DEFAULT)
   1966 //optional - set data and MIME type for the intent
   1967 iImp.setDataAndType(Uri.parse(&quot;http://com.example.project/folder";), &quot;text/plain&quot;); //TODO Change URL and MIME type as appropriate
   1968 startActivityForResult(iImp, 0); //TODO The second parameter (here, zero) is the request code to be used in onActivityResult(); change this parameter to an appropriate value for your activity
   1969           </content>
   1970        </item>
   1971        <item
   1972              description="%intents.send.broadcast.description"
   1973              id="com.motorola.studio.android.codesnippets.item4"
   1974              label="%intents.send.broadcast.label">
   1975           <content>
   1976              //Broadcasts an event notification
   1977 //before sending broadcast, make sure that your application has permission to broadcast the action. Otherwise, a SecurityException: Permission denial will be thrown
   1978 Intent iBroad = new Intent();
   1979 iBroad.setAction(&quot;actionName&quot;); //TODO Replace 'actionName' as appropriate for your action (for example, Intent.ACTION_EDIT)
   1980 iBroad.addCategory(&quot;categoryName&quot;); //TODO Replace 'categoryName' as appropriate for your category (for example, Intent.CATEGORY_DEFAULT) 
   1981 this.sendBroadcast(iBroad);
   1982             
   1983           </content>
   1984        </item>
   1985        <item
   1986              description="%intents.start.service.description"
   1987              id="com.motorola.studio.android.codesnippets.item5"
   1988              label="%intents.start.service.label">
   1989           <content>
   1990              //Starts a service (task to be accomplished in the background, without UI)
   1991 //The class employing the snippet code must implement ServiceConnection
   1992 Intent iServ = new Intent();
   1993 iServ.setClass(getBaseContext(), ServiceName.class); //TODO Replace 'ServiceName' with the class name for your Service
   1994 bindService(iServ, this, BIND_AUTO_CREATE);
   1995 startService(iServ);
   1996           </content>
   1997        </item>
   1998     </category>
   1999     <category
   2000           description="%fragments.ui.description"
   2001           id="android_fragments"
   2002           label="%fragments.ui">
   2003        <item
   2004              description="%fragments.replace.transaction.description"
   2005              id="com.motorola.studio.android.codesnippets.item10"
   2006              label="%fragments.replace.transaction.label">
   2007           <content>
   2008              //Replaces a container's fragment(s)
   2009 FragmentTransaction ft = getFragmentManager().beginTransaction();
   2010 MyFragment newFrag =new MyFragment(); //TODO Change to your fragment constructor
   2011 ft.addToBackStack(null); //Allows this transaction to be undone when the back button is pressed
   2012 ft.replace(R.id.containerId, newFrag, &quot;newFragTag&quot;); //TODO Replace 'R.id.containerId' (with the ID of a View) and 'newFragTag'
   2013 ft.commit();
   2014           </content>
   2015        </item>
   2016        <item
   2017              description="%fragments.add.transaction.description"
   2018              id="com.motorola.studio.android.codesnippets.item11"
   2019              label="%fragments.add.transaction.label">
   2020           <content>
   2021              //Adds a fragment to a specified layout
   2022 FragmentTransaction ft = getFragmentManager().beginTransaction();
   2023 MyFragment newFrag =new MyFragment(); //TODO Change to your fragment constructor
   2024 ft.addToBackStack(null); //Allows this transaction to be undone when the back button is pressed
   2025 ft.add(R.id.layoutId, newFrag); //TODO Replace 'R.id.layoutId' (with the ID of a layout)
   2026 ft.commit();
   2027           </content>
   2028        </item>
   2029     </category>
   2030 	<category
   2031           description="%category.facerecog.description"
   2032           id="face_recognition"
   2033           label="%category.facerecog">
   2034        <item
   2035              description="%snippet.facerecog.description"
   2036              id="com.motorola.studio.android.codesnippets.facerecog1"
   2037              label="%snippet.facerecog.string">
   2038           <content>
   2039              //Make sure the bitmap file was generated using the RGB_565
   2040         //configuration, or else it cannot be used for detection
   2041         //For more information, see  http://developer.android.com/reference/android/media/FaceDetector.html#findFaces(android.graphics.Bitmap, android.media.FaceDetector.Face[])
   2042         BitmapFactory.Options bmpOptions = new BitmapFactory.Options();
   2043         bmpOptions.inPreferredConfig = Bitmap.Config.RGB_565;
   2044         
   2045         //Decode the file from Resources and get some of its parameters.
   2046         //You can also use any of the decode methods from BitmapFactory
   2047         Bitmap bmp = BitmapFactory.decodeResource(getResources(), /*TODO: Insert your drawable resource ID here*/, bmpOptions);
   2048               int MaxNumberOfDetectedFaces = 2;
   2049               
   2050               //Instantiate a vector with the number of faces you want
   2051               Face[] faces = new FaceDetector.Face[MaxNumberOfDetectedFaces];
   2052               //Instantiate a FaceDetector object for the bitmap
   2053               FaceDetector fd = new FaceDetector(bmp.getWidth(), bmp.getHeight(), MaxNumberOfDetectedFaces);
   2054 
   2055               //Use the findfaces() method to actually process the bitmap
   2056               if (fd.findFaces(bmp, faces) &gt; 0) {
   2057                      //Do something here. You can see how accurate the detection was
   2058                      //by calling confidence() on any of the found faces.
   2059 			//In this example, it looks only for the first face (faces[0]).
   2060                      Toast.makeText(this, &quot;Confidence: &quot; + faces[0].confidence(), Toast.LENGTH_SHORT).show();
   2061               }
   2062               else {
   2063                      //No faces were found in the bitmap
   2064                      Toast.makeText(this, &quot;No face found!&quot;, Toast.LENGTH_SHORT).show();
   2065               }
   2066           </content>
   2067        </item>
   2068     </category>
   2069    </extension>
   2070    <extension
   2071          point="org.eclipse.ui.perspectiveExtensions">
   2072       <perspectiveExtension
   2073             targetID="org.eclipse.jdt.ui.JavaPerspective">
   2074          <viewShortcut
   2075                id="org.eclipse.wst.common.snippets.internal.ui.SnippetsView">
   2076          </viewShortcut>
   2077          <view
   2078                id="org.eclipse.wst.common.snippets.internal.ui.SnippetsView"
   2079                minimized="false"
   2080                relationship="stack"
   2081                relative="org.eclipse.ui.views.ContentOutline"
   2082                visible="true">
   2083          </view>
   2084       </perspectiveExtension>
   2085    </extension>
   2086  </plugin>
   2087