Sunday, June 16, 2013

Publishing Android app?

If you're going to publish your app in Google Play store you need to have the below checklist.. Thanks to Ellie Powers for the list.

1. Boost your developer account security

  • If you take just one step today to protect your Google Play apps, enabletwo-step authentication for your Google account, and encourage the rest of your team to do the same.
  • Next, many developers first set up their Google Play account with their personal gmail account, but it’s actually a good idea to transfer your apps to a separate account. All of your installations and reviews remain intact. If you haven’t done this already, transfer your apps to a new account today.
  • Don’t share passwords. Instead, add each individual who needs access and only grant the minimum level of access they need — and encourage them to enable two-step authentication.
  • Review the list of people with access regularly, and when people leave your project, make it a standard practice to remove their access. Learn more about developer account security.

2. Protect your keystore

In order to publish an update to an existing app, you’ll need to sign it with the same keystore every time. If you lose your keystore, you’ll lose your history and reviews, so you’ll need to start over with new apps with new package name and a new key, so you’ll want to make sure you protect it. First, choose a secure password, and don’t use the same password that you use for your Google account. Next, back up your keystore somewhere, but don’t upload it to Google Drive with an account you use to publish on Google Play.

3. Check your email addresses

As a developer, you are responsible for checking two important email addresses:
  • Account owner email address: Google uses the address used to register your Developer Console to contact you about your apps and account, so it is extremely important that someone is responsible for checking it regularly. If necessary, you can forward messages from this account via Gmail, or transfer your apps to another account.
  • Customer support email address: For each individual application, you can specify the best way for users to contact you for customer support. Ensure that a valid support email address for your product is specified. As a best practice, this should probably be a designated support account that is checked regularly and not the same email as the address used to login to the Developer Console.

4. Familiarize yourself with the policies

We recently launched some new guides and examples for Google Play’s Developer Program Policies and Developer Distribution Agreement. Note that once you publish an app as free, you can’t change it to a paid app later, though you can add in-app products.

5. Set up team processes

You may have many people involved with your Google Play apps. Make sure roles are clear in terms of whose job it is to publish updates, check statistics and optimization tips, read and reply to user reviews, and track revenue. Make sure all of these people have the right access to the Developer Console. Many developers who are part of larger organizations also report to their larger teams about their apps’ performance. Designate someone to make sure your app description, graphics (including localized and tablet screenshots), and pricing are up to date.

6. Configure your Developer Console UI languages

To change the language you want to see the Developer Console in, set your primary language. If you speak additional languages, configure those, too — user reviews in those languages won’t be translated automatically in the Developer Console. That was a popular request from developers.

7. Refresh your app’s marketing materials

8. Stay on top of developer news

To make sure you’re aware of the latest Google Play updates for developers, make sure you check the Android Developers blog regularly, follow +Android Developers, and check the Developer Console regularly for announcements.

Friday, June 14, 2013

Missing contentDescription attribute on ImageView in XML - Android



I've the below ImageView in my XML file,

<ImageView  
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:id="@+id/myImgView"
            android:src="@drawable/something"/>

I get a warning saying that [Accessibility]Missing contentDescription attribute on image in Eclipse IDE. Since it is a warning we used to ignore it.. However to overcome this warning, all you need to add is the below piece of code in ImageView,

android:contentDescription="@string/description" (static or dynamic) 

This is helpful for people using alternative input methods because of their disability (like TalkBack, Tecla Access Shield etc)

You can read more about this here http://android-developers.blogspot.in/2012/04/accessibility-are-you-serving-all-your.html

Thursday, June 13, 2013

How to change ImageView Source - Android?

Consider you have set the source for the ImageView in your xml as below,

<ImageView  
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:id="@+id/myImgView"
            android:src="@drawable/something"/>
To change the image source programatically,

myImgView.setImageResource(R.drawable.ball);
or,

myImgView.setImageDrawable(getResources().getDrawable(R.drawable.ball));

GridView scroll - Android


I've a list of images in my app that needs to be shown in a Grid layout.. I've tried many ways to set height in Gridview layout, but all went in vain.. 

After too much of research, I stumbled on the excellent answer of Neil Traft.  I just copy-pasted his code in my app and it worked like a charm :)

ExpandableHeightGridView.java:

public class ExpandableHeightGridView extends GridView
{

    boolean expanded = false;

    public ExpandableHeightGridView(Context context)
    {
        super(context);
    }

    public ExpandableHeightGridView(Context context, AttributeSet attrs)
    {
        super(context, attrs);
    }

    public ExpandableHeightGridView(Context context, AttributeSet attrs,
            int defStyle)
    {
        super(context, attrs, defStyle);
    }

    public boolean isExpanded()
    {
        return expanded;
    }

    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
    {
        // HACK! TAKE THAT ANDROID!
        if (isExpanded())
        {
            // Calculate entire height by providing a very large height hint.
            // But do not use the highest 2 bits of this integer; those are
            // reserved for the MeasureSpec mode.
            int expandSpec = MeasureSpec.makeMeasureSpec(
                    Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
            super.onMeasure(widthMeasureSpec, expandSpec);

            ViewGroup.LayoutParams params = getLayoutParams();
            params.height = getMeasuredHeight();
        }
        else
        {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    }

    public void setExpanded(boolean expanded)
    {
        this.expanded = expanded;
    }
}

embed the GridView inside ScrollView as below,

<ScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <RelativeLayout
        android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <com.droid.gview.ExpandableHeightGridView
       android:id="@+id/dashboard_grid"
       android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:horizontalSpacing="2dp"
    android:isScrollContainer="false"
    android:numColumns="2"
    android:stretchMode="columnWidth"
    android:verticalSpacing="20dp" />
</RelativeLayout>
</ScrollView>    

and lastly set the following,


ExpandableHeightGridView gridview = (ExpandableHeightGridView)  findViewById(R.id.dashboard_grid);
gridview.setExpanded(true);

Monday, April 8, 2013

Capitalize every letter in EditText - Android

I had an interesting usecase in my application, where I need to make EditText uppercase by default.

After googling it for a while found the solution,


EditText someText = (EditText) findViewById(R.id.someText);
someText.setInputType(0x00001001);



This will solve the problem :) Let me know if there are any alternate ways

Wednesday, February 13, 2013

Subdirectories in drawable folder - Android?


In Android SDK documentation, all of the examples shown used @drawable/someimage directly address images that are stored in res/drawable directory..

I wondered will it  be possible to create subfolders under drawable folder.. something like


res/drawable
-- fruits
  -- apple.png
  -- orange.png
-- vegetables
  -- cabbage.png
  -- carrot.png

Later I found that it is not possible to create subfolders under drawable directory.. we need to keep the hierarchy flat. Having subfolders under drawable directory will cause the compiler to fail - preventing R.java from being generated correctly..

So what is the workaround??

We can create subfolders under assets directory and load images from there.


Sample code to load images from Assets directory
InputStream is = null;
try {
    is = this.getResources().getAssets().open("fruits/apple.png");
} catch (IOException e) {
    //something
}

image = BitmapFactory.decodeStream(is);



Wednesday, January 30, 2013

Layouts in Android!!


Layouts in Android:

The UI in Android is a hierarchy of viewgroups and views. The viewgroups will be intermediate nodes in the hierarchy, and the views will be terminal nodes.
For example, in the above main.xml file, the LinearLayout is a viewgroup and the TextView is a view.
Android provides the following standard layouts (viewgroups) that can be used in you Android application.
  • LinearLayout
  • RelativeLayout
  • AbsoluteLayout
  • FrameLayout
  • TableLayout


LinearLayout:

LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. You can specify the layout direction with the android:orientation attribute.
All children of a LinearLayout are stacked one after the other, so a vertical list will only have one child per row, no matter how wide they are, and a horizontal list will only be one row high

RelativeLayout:

In a Relative layout every element arranges itself relative to other elements or a parent element.

In order to specify the position with relation to its parent container, we use android:layout_alignParentTop=“true” and android:layout_alignParentLeft=“true” to align elements to the top-left of the parent container. Then, to align with respect to another element we can use the properties android:layout_alignLeft=“@+id/otherelement” and android:layout_below=“@+id/otherelement”.

AbsoluteLayout:

In absolute layout, we can specify the exact coordinates of each control that we want to place. In absolute layout, we will give the exact X and Y coordinates of each control. You can move them around by changing the android:layout_x and android:layout_y properties within the control.
AbsoluteLayout has been deprecated and is not recommended , as it gets tied to a particular screen size.

FrameLayout:

Frame layout is used when you want to show one item on each screen. Using frame layout, we can have multiple items, but they will be overlapping and only only displaying themselves one at a time.

TableLayout:

A layout that arranges its children into rows and columns. A TableLayout consists of a number of TableRow objects, each defining a row.