Showing posts with label Android - tech. Show all posts
Showing posts with label Android - tech. Show all posts

Thursday, December 12, 2013

refactor a code example using one of the new Android SDKs

there are multiple ways in any development task to solve the problem, but the refactor below takes advantage of the object animator and results in a more than 50% code saving. Since it's been a few weeks, I'm posting both the original and the refactored MainActivity.java file. 
Code Listing #1: Using the Object Animator
public class MainActivity extends Activity implements OnClickListener{

 private boolean isHere;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  isHere = true;
  findViewById(R.id.here_button).setOnClickListener(this);
  findViewById(R.id.there_button).setOnClickListener(this);
 }

 @Override
 public void onClick(View v) {
  View cursor = findViewById(R.id.cursor);
  float diff;
  if (v.getId()==R.id.here_button && !isHere) {
   diff = (float) (cursor.getX() - v.getX() - v.getWidth());
   ObjectAnimator.ofFloat(cursor, "translationX", diff, 0).setDuration(1000).start();
   isHere=true;
  } else if (v.getId()==R.id.there_button && isHere) {
   diff = v.getX() - cursor.getX() - cursor.getWidth();
   ObjectAnimator.ofFloat(cursor, "translationX", 0, diff).setDuration(1000).start();
   isHere=false;
  }
 }
 
}
Code Listing #2: Original MainAcitvity.java
MainActivity extends Activity implements OnClickListener, AnimationListener {

 private final static int HERE = -1;
 private final static int THERE = 1;
 private TranslateAnimation anim;
 private View cursor;
 private int screenWidth;
 private int centerOfScreen;
 private int dest;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  screenWidth = (int) (getWindowManager().getDefaultDisplay().getWidth());
  centerOfScreen = (int) (screenWidth *.5);
  cursor = findViewById(R.id.cursor);
  findViewById(R.id.here_button).setOnClickListener(this);
  findViewById(R.id.there_button).setOnClickListener(this);
 }

 @Override
 public void onClick(View v) {
  if (v.getId()==R.id.here_button) {
   animate(HERE);
  } else {
   animate(THERE);
  }
 }
 
 private void animate(int whichWay) {
  if (anim!=null && !anim.hasEnded()) return;
  float target;
  int currentX = cursor.getLeft();
  if (whichWay==HERE ) {
   if (currentX+cursor.getWidth()<=centerOfScreen) return;
   target = (currentX - 
     (findViewById(R.id.here_button).getLeft() + findViewById(R.id.here_button).getWidth()))*-1;
  } else {
   if (currentX>centerOfScreen) return;
   target = findViewById(R.id.there_button).getLeft() - (currentX + cursor.getWidth());
  }
  anim = new TranslateAnimation( TranslateAnimation.ABSOLUTE,0,
         TranslateAnimation.ABSOLUTE,target,
         TranslateAnimation.ABSOLUTE,0.0f,
         TranslateAnimation.ABSOLUTE,0.0f);
  anim.setDuration(500);
  dest = (int) target+cursor.getLeft()+cursor.getWidth();
        anim.setAnimationListener(this);
        cursor.startAnimation(anim);
 }

 @Override
 public void onAnimationEnd(Animation arg0) {
  RelativeLayout.LayoutParams params = 
    new RelativeLayout.LayoutParams(cursor.getWidth(), cursor.getHeight());
  if (dest >= centerOfScreen) {
   params.addRule(RelativeLayout.LEFT_OF, R.id.there_button);
  } else {
   params.addRule(RelativeLayout.RIGHT_OF, R.id.here_button);
  }
  params.addRule(RelativeLayout.CENTER_VERTICAL);
  cursor.setLayoutParams(params);
 }

 @Override
 public void onAnimationRepeat(Animation arg0) {
  // TODO Auto-generated method stub
  
 }

 @Override
 public void onAnimationStart(Animation arg0) {
  // TODO Auto-generated method stub
  
 }
 
}

Tuesday, February 19, 2013

Android Launcher Icons

http://developer.android.com/guide/practices/ui_guidelines/icon_design_launcher.html

http://forumone.com/blogs/post/how-publish-your-mobile-app-google-play-and-apple-app-stores


Size and Format


Launcher icons should be 32-bit PNGs with an alpha channel for transparency. The finished launcher icon dimensions corresponding to a given generalized screen density are shown in the table below.
Table 1. Summary of finished launcher icon dimensions for each generalized screen density.
ldpi (120 dpi)
(Low density screen)
mdpi (160 dpi)
(Medium density screen)
hdpi (240 dpi)
(High density screen)
xhdpi (320 dpi)
(Extra-high density screen)
Launcher Icon Size36 x 36 px48 x 48 px72 x 72 px96 x 96 px
You can also include a few pixels of padding in launcher icons to maintain a consistent visual weight with adjacent icons. For example, a 96 x 96 pixel xhdpi launcher icon can contain a 88 x 88 pixel shape with 4 pixels on each side for padding. This padding can also be used to make room for a subtle drop shadow, which can help ensure that launcher icons are legible across on any background color.

Application Icons on Google Play

If you are publishing your app on Google Play, you will also need to provide a 512 x 512 pixel, high-resolution application icon in the developer console at upload time. This icon will be used in various locations on Google Play and does not replace your launcher icon.
For tips and recommendations on creating high-resolution launcher icons that can easily be scaled up to 512x512, see Tips for Designers.
For information and specifications about high-resolution application icons on Google Play, see the following article:

Tuesday, February 12, 2013

error: cannot spawn D:\Program Files\TortoiseGit\bin\TortoisePLink.exe: No such file or directory fatal: unable to fork


error: cannot spawn D:\Program Files\TortoiseGit\bin\TortoisePLink.exe: No such file or directory
fatal: unable to fork


I got this error when I clone the repository from Bitbucket. Then I got the idea from the link http://www.techneiq.com/2012/08/error-cannot-spawn-cprogram.html?showComment=1360650218892#c1047110200586755151

And I just make a copy of the TortoiseGit folder from C:\Program Files\TortoiseGit\ to D:\Program Files\.

It surprisingly worked for me without modifying anything else.