Android controlling EditText input

Description: coming soon..


  • imeOptions flagNoFullscreen
  • imeOptions actionDone
  • inputType textUri



        <EditText
            android:key="server_ip"
            android:title="server_ip"
            android:dialogTitle="@string/server_ip"
            android:contentDescription="Server IP"
            android:defaultValue="192.168.1.2"
            android:lines="1"
            android:imeOptions="flagNoFullscreen|actionDone"
            android:inputType="textUri"/>


As an Amazon Associate I earn from qualifying purchases.

Android: using AIDL

DEFINING AIDL OBJECTS


Let's say we want to define AIDL that we will use to communicate UI Fragment with AndroidService.

/** calls UI to Service **/
MyServiceAIDL.aidl

interface CommandServiceAIDL {
void setSomething(double value);
}



/** callbacks service to UI **/
MyListenerAIDL.aidl

interface MyListenerAIDL {
void onSomeEvent( boolean isOn);
}



ONCE YOU HAVE YOUR AIDL DEFINED



Let's say we have a UI Fragment

import android.content.ServiceConnection;

public class MyFragment extends Fragment implements ServiceConnection {
// ...
 @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
    // we have to BIND this UI to AIDL service
      getActivity().getApplicationContext().bindService(new Intent(CommandConst.ACTION_BIND_SERVICE), this, Context.BIND_AUTO_CREATE);
   }


// ...
@Override
   public void onDestroy() {
      super.onDestroy();
     // WE have to UNBIND this UI form AIDL service
      getActivity().getApplicationContext().unbindService(this);
   }



// class that has all my AIDL methods
private MyServiceAIDL myServiceAIDL;

@Override
   public void onServiceConnected(ComponentName name, IBinder service) {
   
      myServiceAIDL = MyServiceAIDL.Stub.asInterface(service);
      try {
         // register this fragment as a client of the AIDL service
         myServiceAIDL.register(TAG, myServiceAIDL Callback);
         myServiceAIDL.setSomething(123.5);
      }
      catch (RemoteException e) {
         Log.e(TAG, e.getMessage(), e);
      }
   }


private void doSomething(double value) {
         try {
            myServiceAIDL.setSomething(value);
         }
         catch (RemoteException e) {
            e.printStackTrace();
         }
      }


 // CALLBACKS

 private final MyListenerAIDL.Stub commandServiceCallback = new SimpleCommandServiceListener() {

     @Override
      public void onSomeEvent(final boolean isOn) throws RemoteException {
         handler.post(new Runnable() {
            @Override
            public void run() {
               if (someSwitch.isChecked() != isOn) {
                  someSwitch.setChecked(isOn);
               }
            }
         });
      }
}


As an Amazon Associate I earn from qualifying purchases.

Android app deploying and monetizing

In this tutorial we will discuss what you need to do to deploy your app to the Google Play Market and how to make money $$$.


Google Play Account


To start deploying apps you will need an account with play.google.com/apps/publish/ . This will cost you one time about $25 fee. 


Uploading new app:

Creating New Key Store

  • create one Key Store per application in case you want to sell or transfer it later
  • use separate passwords for New Key Store and the app-specific Key inside





Once you created a Key Store you can "Generate Signed APK..."





Android Studio can remember your passwords, but you have to set a master password for that.



Upload signed APK to Google Play Market






Once you deploy your app you will be able to monitor various things such as:
  • installs / uninstalls
  • upgrades




Marketing, marketing, and marketing

Marketing is essential for success of your app, it often takes more time and money to market the app than to write the code. This is where we often fail as developers.
  • marketing of a bad product is a waste of money
  • not marketing of a good product is sad
  • build in social sharing features
  • issues of selling and marketing with children apps


Monitoring Tools: Flurry



Monetizing your apps

  • develop apps on topic that is useful to YOU, not others -- You will need the fuel for burning that midnight oil, lots of it!
  • develop multiple apps -- you can never say which "floppy birds" will be successful
  • monitor statistics and adjust accordingly
  • deploy updates often (fix bugs, improve UX)
  • use freemium model unless you are selling an established product that everyone needs
  • in-app purchases (pic below)
  • advertisement model (pic below)
  • donation model -- people too busy to donate
  • free app - make money on your core business (consulting, etc.)


In app purchases: you can specify multiple products



In app purchases "trickle" revenue.





AdMob example of "trickle" revenue.








Do I need Apple iOS version for each of my Android apps?


No, I have developed many, many Android and iOS pairs of apps and I learned one thing:

"If you did not make enough money on your Android app to pay for Apple iOS version development and marketing costs (say.. a million $$$), then keep on developing Android apps until you do; and don't listen to iPhone owners who really want it, it is just not worth it."




As an Amazon Associate I earn from qualifying purchases.

Android Studio: migrating to 1.0

Exciting moment -- Android Studio is not a baby anymore!
However, the rite of passage did not come without the growing pains.




The application icon: what happened? We went quite cute and beloved robot (left) to what may be described as an adolescent imitation of Freemasons symbol (center).. some kind of grandiose undercurrents? Not cool.



OK, so the icon is PLAIN UGLY, I guess there is a trend there and everyone is jumping on this bandwagon, give it few years, we will come back to pretty candy-like icons.

Migrating the projects... 

it is really a shame that a project created with Android Studio a 3 days ago cannot be run today, not a big deal to me, but my students who are new to computer science will be thrown off.

Actually, I gave up on trying to UPDATE my project and just created new one, then copied my modules over to it. Not cool, but it worked just fine.

Please note the following:

1) in your main project (e.g. CIT299) build.gradle

    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'


2) in ALL your modules build.gradle REPLACE runProguard false with minifyEnabled true

   buildTypes {
        release {
            runProguard false           
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

        }
    }


    buildTypes {
        release {
            apply plugin: 'maven'
            apply plugin: 'eclipse'
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }




After that I was able to run everything, so it is not a huge deal.

Now, I can sit and watch the Memory Monitor for Facebook eating all my memory :)




If you like this post, please give me your 2 cents ($0.02 litterally) to show token of appreciation and encourage me to write more:

Donate Bitcoins



As an Amazon Associate I earn from qualifying purchases.

Mac OS X: cpp tools

In this tutorial I will summarize how to install all tools needed to compile C++ code.

Install Apple's Command Line Tools:

$ xcode-select --install

xcode-select: error: command line tools are already installed, use "Software Update" to install updates






As an Amazon Associate I earn from qualifying purchases.

SMS bid app



README.md

*************************************************
APP OVERVIEW
*************************************************

Use cases:
1) User creates offline list of items that will be used in an auction, example:
- sofa, pale blue, heavily used #sofa001
- mountain bike, barely used (I am developer not a sportsman) #bike002
- HTC ONE, Android phone, still working, AT&T #phone003
2) User distributes the list of bid items to FFF (family, friends and fools) by mailing, posting, etc.
3) User enters the bid items into the app
4) User enters the bid deadline per item into the app
6) User enters a minimum bid price per item into the app
7) FFF send SMS messages with bid in format:

bid #bike002 $30

8) The app tally up the highest bid and replies to FFF

- Minimum bid for item #bike002 is $30
- These is a higher bid for #bike002 in amount of $31

9) User can monitor the winning bids in the app

#sofa001
No bids

#bike002 minimum bid $30
- $31 from 6508151234
- $30 from 6508151432

10) there are many additional features you can add to this application


Step 1) Copy appSMS


We will use the previous app we wrote as a starting point.
Synch the class GIT repo:
- git fetch
- git add -all
- git commit -m "my previous changes xyz"
- git rebase
- git push
You can copy the version committed by the instructor to your desktop and then "Import Module" in AndroidStudio
Name it appSMSBid

Step 2) Rename the app in res/values/strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">"SMS Auction"</string>
    <string name="action_settings">Settings</string>
</resources>


Step 3) Change the package name (app unique identifier)


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.chicagoandroid.android.app.sms.bid">

Step 4) Move classes


  • Create new package bid
  • Move classes to package com.chicagoandroid.android.app.sms.bid

Step 5) Run the app


adb shell 'pm list packages -f' | grep /data/app/com.chicagoandroid.android.app.sms

Step 6) see what class apps you have running


$ adb shell 'pm list packages -f' | grep /data/app/com.chicagoandroid.android.app

package:/data/app/com.chicagoandroid.android.app.sms-1.apk=com.chicagoandroid.android.app.smspackage:/data/app/com.chicagoandroid.android.app.json.weather-1.apk=com.chicagoandroid.android.app.json.weather

Step 7) Create a new Java class BidItem.java





  •  private String description;
  •  private String itemID;
  •  private double minBidPrice;


  • Generate Getters and Setters methods




    Add constructor:

       BidItem(String itemID, double minBidPrice, String description) {
          this.setDescription(description);
          this.setItemID(itemID);
          this.setMinBidPrice(minBidPrice);
       }


    Override default toString method:


       @Override
       public String toString() {
          StringBuffer output = new StringBuffer(150);
          output.append("itemID: " + getItemID() + ", ");
          output.append("description: " + getDescription() + ", ");
          output.append("minBidPrice: $" + getMinBidPrice());
          return output.toString();
       }





    Step 8: Create Java class Bid

    constructor:

       Bid(String bidID, double bidAmount, String personNumber) {
          this.setBidID(bidID);
          this.setBidAmount(bidAmount);
          this.setPersonNumber(personNumber);
       }







    Step 9: Create class BidEngine


    package com.chicagoandroid.android.app.sms.bid;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    /**
     * Created by uki on 12/6/14.
     */
    public class BidEngine {
       /** A collection of BidItems indexed by itemID **/
       private Map<String, BidItem> bidItems;
       private List<Bid> bids;
       BidEngine() {
          createMockBidItems();
          createMockBids();
       }
       //TODO public void addItem(BidItem)
       //TODO public void removeItem(BidItem)
       //TODO public void changeItem(BidItem);
       public Map getBidItems() {
          return this.bidItems;
       }
       private void createMockBidItems() {
          bidItems = new HashMap<String, BidItem>();
          BidItem sofa = new BidItem("sofa001", 15.00, "sofa, pale blue, heavily used");
          bidItems.put(sofa.getItemID(), sofa);
          BidItem bike = new BidItem("bike002", 50.00, "mountain bike, barely used (I am developer not a sportsman)");
          bidItems.put(bike.getItemID(), bike);
          BidItem phone = new BidItem("phone003", 30.00, "HTC ONE, Android phone, still working, AT&T");
          bidItems.put(phone.getItemID(), phone);
       }
       private void createMockBids() {
          bids = new ArrayList<Bid>();
          Bid sofa1 = new Bid("sofa001", 15.00, "6508151234");
          bids.add(sofa1);
          Bid sofa2 = new Bid("sofa001", 16.00, "6508151232");
          bids.add(sofa2);
          Bid sofa3 = new Bid("sofa001", 17.00, "6508151234");
          bids.add(sofa3);
       }
       public String printMyBidItems() {
          StringBuffer output = new StringBuffer();
          for (BidItem item : bidItems.values()) {
             output.append(item.toString() + "\n");
          }
          return output.toString();
       }
    }




    Step 10: Create initial UI









    As an Amazon Associate I earn from qualifying purchases.

    AndroidStudio: install *.md plugin

    It is a common practice to provide a README text file in the root of the project.
    The file usually specify:
    - project overview
    - project dependencies
    - how to build the project
    - copyrights

    It is became the standard to write this file in a MarkDown format README.md

    Once you create a new *.md text file the AndroidStudio tells you that it does not recognize the format and to download the plugin.



    As an Amazon Associate I earn from qualifying purchases.

    My favorite quotations..


    “A man should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects.”  by Robert A. Heinlein

    "We are but habits and memories we chose to carry along." ~ Uki D. Lucas


    Popular Recent Articles