Tuesday, 3 September 2013

Splash screen in android

1) Create a class splash screen.xml
========================

    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

            android:id="@+id/img_splash"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/splash_screen" />



2)create java file named SpashScreen.java
================================
package com.drc.donateandalarm;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;

public class SplashScreen extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.xsplashscreen);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

        if(Calander_Manage.session){
              Calander_Manage.Set_DayLight_Saving(this);
        }
        thread.start();
    }
   
    // This Is run when key down
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
   
    private Handler handler = new Handler();
    private Thread thread = new Thread() {
        public void run() {
                try {
                        Thread.sleep(2000);
                        handler.post(mRunnable);
                }
                catch (Exception e) {
                    e.printStackTrace();
                }
        }
    };
   
    private Runnable mRunnable = new Runnable()
    {
        public void run()
        {      
            Intent iv = new Intent(SplashScreen.this,HomeActivity.class);
            startActivity(iv);
            finish();
        }
    };

}

Thursday, 29 August 2013

Database link

http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/

Thursday, 15 August 2013

Create buttons using shape


//create xml button_big_normal.xml




android:shape="rectangle"

android:useLevel="false">




android:color="#adadac"/>


android:bottomRightRadius="10dp"

android:topLeftRadius="10dp"

android:topRightRadius="10dp"/>

//Create xml button_big_selected.xml  


android:shape="rectangle"

android:useLevel="false">


android:color="#000000"/>


android:color="#adadac"/>


android:bottomLeftRadius="10dp"

android:bottomRightRadius="10dp"

android:topLeftRadius="10dp"

android:topRightRadius="10dp" />

  //Create xml button_big.xml

Wednesday, 14 August 2013

create button using shape in android

http://stackoverflow.com/questions/2122199/how-do-i-set-the-rounded-corner-radius-of-a-color-drawable-using-xml


    android:shape="rectangle">
            android:startColor="#679a00"
        android:endColor="#98cb00"
        android:angle="90"/>
            android:top="6dp"
        android:right="6dp"
        android:bottom="6dp" />
   

Sunday, 11 August 2013

shared preference android

SharedPreferences sp_Detail = getSharedPreferences(Constant.
SHAREDPREFERENCES
, MODE_WORLD_WRITEABLE);
SharedPreferences.Editor spEdit_Event = sp_Detail.edit();
spEdit_.putString(Constant.
_ID, alst_Id.get(position));
spEdit_.putString(Constant.
_NAME, alst_Title.get(position));spEdit_.commit();






SharedPreferences ShareEvent = getSharedPreferences(Constant.
SHAREDPREFERENCES, MODE_WORLD_READABLE);
strEventID = ShareEvent.getString(Constant.EVENT_ID,null);

SVN Use

// open eclips click hep => Install software =>

In Work with textview add

http://subclipse.tigris.org/update_1.6.x

Then click on select All => Next


After installing SVN right click on project=>Team=>Share project
and give path to svn(eg:http://192.168.2.201:8080/svn/asteroid_android/)

Click on file which you want to edit lock this file
After updating unlock this file

tab implementation in android

//create xml tab.xml
****************

xml version="1.0"
encoding="utf-8"?>
<
TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
</FrameLayout>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
/>
</LinearLayout>
</TabHost>

//Create java file HomeActivity.java
****************************
package com.mrs.abd;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TextView;

public class HomeActivity extends  android.app.TabActivity implements OnTabChangeListener {
 private TabHost tabHost = null;
 private TextView txtHome  = null,txtDoneer = null,txtDelen= null,txtOver = null;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  requestWindowFeature(Window.FEATURE_NO_TITLE);
  setContentView(R.layout.tabs);

  tabHost = (TabHost)findViewById(android.R.id.tabhost);

  TabHost.TabSpec spec;
  Intent intent;

  intent = new Intent().setClass(this, ViewGroupOrganizer.class);
  txtHome = new TextView(this);
  txtHome.setTypeface(CommanClass.SetCustomFont(getResources()));
  txtHome.setText(Constant.HOME_TAB_TEXT);
  txtHome.setTextColor(getResources().getColor(R.color.White));
  txtHome.setBackgroundResource(R.drawable.img_tab_home_selected);
  txtHome.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
  txtHome.setGravity(Gravity.CENTER);
  spec = tabHost.newTabSpec(Constant.1_TAB_TEXT).setIndicator(txtHome).setContent(intent);
  tabHost.addTab(spec);

  txtDe = new TextView(this);
  txtDe.setTypeface(CommanClass.SetCustomFont(getResources()));
  txtDe.setText(Constant.2_TAB_TEXT);
  txtDe.setTextColor(getResources().getColor(R.color.Black));
  txtDe.setBackgroundResource(R.drawable.img_tab_doneer);
  txtDe.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
  txtDe.setGravity(Gravity.CENTER);
  spec = tabHost.newTabSpec(Constant.3_TAB_TEXT).setIndicator(txtDelen).setContent(intent);
  tabHost.addTab(spec);

  intent = new Intent().setClass(this, Do.class);
  txtDo = new TextView(this);
  txtDo.setText(Constant.DO_TAB_TEXT);
  txtDo.setTypeface(CommanClass.SetCustomFont(getResources()));
  txtDo.setTextColor(getResources().getColor(R.color.Black));
  txtDo.setBackgroundResource(R.drawable.img_tab_doneer);
  txtDo.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
  txtDo.setGravity(Gravity.CENTER);
  spec = tabHost.newTabSpec(Constant.DOTAB_TEXT).setIndicator(txtDoneer).setContent(intent);
  tabHost.addTab(spec);

  intent = new Intent().setClass(this, Over.class);
  txtO = new TextView(this);
  txtO.setTypeface(CommanClass.SetCustomFont(getResources()));
  txtO.setText(Constant.3_TAB_TEXT);
  txtO.setTextColor(getResources().getColor(R.color.Black));
  txtO.setBackgroundResource(R.drawable.img_tab_over);
  txtO.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
  txtO.setGravity(Gravity.CENTER);
  spec = tabHost.newTabSpec(Constant.3_TAB_TEXT).setIndicator(txtOver).setContent(intent);
  tabHost.addTab(spec);

  tabHost.setCurrentTab(0);

  tabHost.getTabWidget().getChildAt(0).setOnClickListener(new OnClickListener()
  {
   @Override
   public void onClick(View v)
   {
    if(tabHost.getCurrentTab()==0)
    {
     while(true)
     {
      if (ViewGroupOrganizer.history.size() > 1)
      {
       ViewGroupOrganizer.history.remove(ViewGroupOrganizer.history.size() - 1);
       ViewGroupOrganizer.group.setContentView(ViewGroupOrganizer.history.get(ViewGroupOrganizer.history.size() - 1));
      }
      else
      {
       break;
      }
     }
    }
    else
    {
     tabHost.setCurrentTab(0);
    }
   }
  });

  tabHost.getTabWidget().getChildAt(1).setOnClickListener(new OnClickListener()
  {
   @Override
   public void onClick(View v)
   {
    ShareAlertdialog();
   }
  });
  tabHost.setOnTabChangedListener(this);
 }

//***********************************************************************************************************************
/**
 * @author Manisha
 * @param none
 * @return void
 * @use This Dialog is used for show share dialog
 */ 
 public void ShareAlertdialog() {
  final CharSequence[] items = { Constant.FACEBOOK, Constant.TWITTER};
  AlertDialog.Builder builder = new AlertDialog.Builder(this);
  builder.setTitle(Constant.SHARE_ALERT_DIALOG_TITLE);
  builder.setNegativeButton(Constant.SHARE_CANCEL_BUTTON, null);
  builder.setItems(items, new DialogInterface.OnClickListener() {
   public void onClick(DialogInterface dialog, int item) {
    if (item == 0) {
     if(CommanClass.CheckNetwork(HomeActivity.this)){
       Intent mIntent = new Intent(HomeActivity.this,Share_On_Facebook.class);
       mIntent.setAction(Constant.FACEBOOK_ACTION);
          startActivity(mIntent);
     }
    } else if(item == 1) {
     if(CommanClass.CheckNetwork(HomeActivity.this)){
      Intent mIntent = new Intent(HomeActivity.this,Share_On_Twitter.class);
         mIntent.setAction("");
               startActivity(mIntent);
     }
    }
   }
  });
  AlertDialog alert = builder.create();
  alert.show();
 }

  @Override
 public void onTabChanged(String tabId) {
  if(tabId.equals(Constant.HOME_TAB_TEXT)){
   txtHome.setBackgroundResource(R.drawable.img_tab_home_selected);
   txtHome.setTypeface(CommanClass.SetCustomFont(getResources()));
   txtHome.setTextColor(getResources().getColor(R.color.White));
  }
  else{
   txtHome.setBackgroundResource(R.drawable.img_tab_home);
   txtHome.setTypeface(CommanClass.SetCustomFont(getResources()));
   txtHome.setTextColor(getResources().getColor(R.color.Black));
  }
  if(tabId.equals(Constant.DONEER_TAB_TEXT)){
   txtDo.setBackgroundResource(R.drawable.img_tab_doneer_selected);
   txtDo.setTypeface(CommanClass.SetCustomFont(getResources()));
   txtDo.setTextColor(getResources().getColor(R.color.White));
  }
  else{
   txtDo.setBackgroundResource(R.drawable.img_tab_doneer);
   txtDo.setTypeface(CommanClass.SetCustomFont(getResources()));
   txtDo.setTextColor(getResources().getColor(R.color.Black));
  }
  if(tabId.equals(Constant.4TAB_TEXT)){
   txt4.setBackgroundResource(R.drawable.img_tab_doneer_selected);
   txt4.setTypeface(CommanClass.SetCustomFont(getResources()));
   txt4.setTextColor(getResources().getColor(R.color.White));
  }
  else{
   txt4setBackgroundResource(R.drawable.img_tab_doneer);
   txt4setTypeface(CommanClass.SetCustomFont(getResources()));
   txt4setTextColor(getResources().getColor(R.color.Black));
  }
  if(tabId.equals(Constant.4TAB_TEXT)){
   txt4setBackgroundResource(R.drawable.img_tab_4selected);
   txt.setTypeface(CommanClass.SetCustomFont(getResources()));
   txt4setTextColor(getResources().getColor(R.color.White));
  }
  else{
   txt4setBackgroundResource(R.drawable.img_4over);
   txt4setTypeface(CommanClass.SetCustomFont(getResources()));
   txt4setTextColor(getResources().getColor(R.color.Black));
  }
 }
}


//code for Give space in tab 
TabWidget widget = getTabWidget();
        final int tabChildrenCount = widget.getChildCount();
        LinearLayout.LayoutParams currentLayout;
        for (int i_tab = 0; i_tab < tabChildrenCount; i_tab++) {
            currentLayout = (LinearLayout.LayoutParams) widget
                    .getChildAt(i_tab).getLayoutParams();
            if (i_tab == 0) {
                currentLayout.setMargins(10, 0, 5, 0);
            } else if (i_tab == (tabChildrenCount - 1)) {
                currentLayout.setMargins(5, 0, 10, 0);
            } else {
                currentLayout.setMargins(5, 0, 5, 0);
            }
            currentLayout.height = 40;
        }
        widget.requestLayout();