Android Application Architecture:










Android Application Architecture has following components such as
Services, Intent, Resources Externalization, Notification signaling users, Content providers



Dalvik Virtual Machine
It is optimizes the JVM for memory,battery,performance. It optimized for mobile devices.

Activities
An activity represents a single screen with user interface.
 public void MyActivity extends Activity{  
 }  

Service
Service is like an Activity but has no interface. It is component that runs in background for long running process eg: music player
Types:
  • Unbound Services 
    • It runs in the background indefinitely, even if the activity which started this  service ends.
  • Bound Services
    • It runs till lifespan of the activity which started this service. Client-Server interface.
 public void MyService extends Service{  
 }  
 <service android:name=”.MyService”/>  

Intent
Describing specific action. 
Types:
  • Implicit Intent
    • It redirect from Activity in application to external application activity.
    •  Uri uri = Uri.parse(“http://www.google.com”);  
       Intent i = new Intent(Intent.ACTION_VIEW,uri);  
       startActivity(i);  
      
  • Explicit Intent
    • It redirect from Activity to another Activity in application.
    •  Intent i = new Intent(this,SecondActivity.class);  
       startActivity(i);  
      

BroadcastReceiver
It simply respond to broadcast messages from other applications or from the system.
 public class MyReceiver extends BroadcastReceiver{  
 public void onReceive(Context context,Intent intent){}  
 }  

Content Providers
A content provider component supplies data from one application to others on request.


Implementing custom font in whole application is very easy. We can set any custom font to our whole android application just like a theme. This is very simple procedure and easy to implements. 

Needs:

  • Custom font (stored in Asset folder)
  • Commonfont util to apply font for TextView,Button,EditText,CheckBox etc.. in whole application


CommonFont.java


 import android.content.Context;  
 import android.graphics.Typeface;  
 import android.util.Log;  
 import android.view.View;  
 import android.view.ViewGroup;  
 import android.widget.Button;  
 import android.widget.CheckBox;  
 import android.widget.EditText;  
 import android.widget.RadioButton;  
 import android.widget.TextView;  
 public class CommonFont {  
      public static void setfont(final Context context, final View viewroot, final String fontpath) {  
           try {  
                if(viewroot instanceof ViewGroup) {  
                     ViewGroup viewgroup = (ViewGroup) viewroot;  
                     int childCount = viewgroup.getChildCount();  
                     for (int i = 0; i < childCount; i++){  
                          setfont(context, viewgroup.getChildAt(i),fontpath);  
                     }  
                }else if (viewroot instanceof TextView)  
                     ((TextView) viewroot).setTypeface(Typeface.createFromAsset(context.getAssets(), fontPath));  
                 else if (viewroot instanceof Button)  
                          ((Button) viewroot).setTypeface(Typeface.createFromAsset(context.getAssets(), fontPath));  
                 else if (viewroot instanceof EditText)  
                          ((EditText) viewroot).setTypeface(Typeface.createFromAsset(context.getAssets(), fontPath));  
                 else if (viewroot instanceof CheckBox)  
                          ((CheckBox) viewroot).setTypeface(Typeface.createFromAsset(context.getAssets(), fontPath));  
           } catch (Exception e) {  
                e.printStackTrace();  
           }  
      }  
 }

In Activity:
Just use like below

 CommonFont.setfont(context, findViewById(R.id.container),"font/Roboto.ttf");  

 View view;  
 CommonFont.setfont(context, view,"font/Roboto.ttf");  

In Android we use ARGB, so Transparency take part as below

100% —  FF
95% —    F2
90% —    E6
85% —    D9
80% —    CC
75% —    BF
70% —    B3
65% —    A6
60% —    99
55% —    8C
50% —    80
45% —    73
40% —    66
35% —    59
30% —    4D
25% —    40
20% —    33
15% —    26
10% —    1A
5% —      0D
0% —      00



A- ff (Opacity)
R- 4c (Red)
G- bc (Green)
B- 5f (Blue)
To Generate Facebook Hash key by using two steps.

  • via command prompt (already discussed in previous POST)
  • via coding
By generate hash key using command prompt will work first time only after that it will not works and also got the same issuesSo, go-head by programmatically generation.

Steps to generate hash key:
  • paste below coding in onCreate()
 try {  
      PackageInfo info = getPackageManager().getPackageInfo(  
                "com.facebook.samples.hellofacebook",   
                PackageManager.GET_SIGNATURES);  
      for (Signature signature : info.signatures) {  
           MessageDigest md = MessageDigest.getInstance("SHA");  
           md.update(signature.toByteArray());  
           Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));  
           }  
 } catch (NameNotFoundException e) {  
 } catch (NoSuchAlgorithmException e) {  
 }  

Change "com.facebook.samples.hellofacebook" with your package name in the above coding without fail(You may found your package name in Android Manifest file).
Steps To Generate android Hash Key for Facebook:

  • Download OpenSSL for Windows
  • Extract your Open SSL zip in root directory or any where in your drive
  • Open %extracted folder%\openssl-0.9.8k_WIN32\bin there you can see openssl.exe
  • From Shift + Right mouse click to open Command prompt
  • Now start from here
    • paste below text in cmd
    • keytool -exportcert -alias androiddebugkey -keystore C:\Users\%user%\.android\debug.keystore | openssl sha1 -binary | openssl base64
  • Then enter keystore password
  • You are ready to get Hash Key :)
Shrink Bitmap:

 public Bitmap ShrinkBitmap(String file, int width, int height){  
  BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();  
      bmpFactoryOptions.inJustDecodeBounds = true;  
      Bitmap bitmap = BitmapFactory.decodeFile(file, bmpFactoryOptions);  
      int heightRatio = (int)Math.ceil(bmpFactoryOptions.outHeight/(float)height);  
      int widthRatio = (int)Math.ceil(bmpFactoryOptions.outWidth/(float)width);  
      if (heightRatio > 1 || widthRatio > 1)  
      {  
       if (heightRatio > widthRatio)  
       {  
       bmpFactoryOptions.inSampleSize = heightRatio;  
       } else {  
       bmpFactoryOptions.inSampleSize = widthRatio;  
       }  
      }  
      bmpFactoryOptions.inJustDecodeBounds = false;  
      bitmap = BitmapFactory.decodeFile(file, bmpFactoryOptions);  
  return bitmap;  
 }  

Cropped Bitmap:

 public Bitmap getCroppedBitmap(Bitmap bitmap) {  
      Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),  
                bitmap.getHeight(), Config.ARGB_8888);  
      Canvas canvas = new Canvas(output);  
      final int color = 0xff424242;  
      final Paint paint = new Paint();  
      final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());  
      paint.setAntiAlias(true);  
      canvas.drawARGB(0, 0, 0, 0);  
      paint.setColor(color);  
      // canvas.drawRoundRect(rectF, roundPx, roundPx, paint);  
      canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2,  
                bitmap.getWidth() / 2, paint);  
      paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));  
      canvas.drawBitmap(bitmap, rect, rect, paint);  
      //Bitmap _bmp = Bitmap.createScaledBitmap(output, 60, 60, false);  
      //return _bmp;  
      return output;  
 }  

      public void appendLogger(String text)  
      {      
        File logFile = new File("/mnt/sdcard/log.file");  
        if (!logFile.exists())  
        {  
         try  
         {  
           logFile.createNewFile();  
         }   
         catch (IOException e)  
         {  
           // TODO Auto-generated catch block  
           e.printStackTrace();  
         }  
        }  
        try  
        {  
         //BufferedWriter for performance, true to set append to file flag  
         BufferedWriter buf = new BufferedWriter(new FileWriter(logFile, true));   
         buf.append(text);  
         buf.newLine();  
         buf.close();  
        }  
        catch (IOException e)  
        {  
         // TODO Auto-generated catch block  
         e.printStackTrace();  
        }  
      }