Pages

Tuesday 2 August 2011

Splash Class Example In Android

public class splash extends Activity{
   
    private boolean _enableAutoSMS;//CheckboxPreference;
    String _listPreference1,_listPreference2,_listPreference3,_listPreference4,_listPreference5,_listPreference6;
    String editTextPreference;
    String ringtonePreference;
    String secondEditTextPreference;
    String customPref;
   
    private String _preference = "FreeBetting" ;   
    private SharedPreferences _sharedPreference;
    private Editor _editor;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
       
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.splash);
        _sharedPreference = getSharedPreferences("Photo Share", Context.MODE_PRIVATE);
        _editor = _sharedPreference.edit();
        new Handler().postDelayed(new Runnable() {
           
            @Override
            public void run() {
                splash.this.startActivity(new Intent(splash.this,UserLogin.class));
                splash.this.finish();
           
            }
        }, 2540);
    }
       
    @Override
    protected void onStart() {
        // TODO Auto-generated method stub
        super.onStart();
    }
   
}

By:Parmil.S &VkHooda

Utils In android

import java.io.InputStream;
import java.io.OutputStream;

public class Utils {
    public static void CopyStream(InputStream is, OutputStream os)
    {
        final int buffer_size=1024;
        try
        {
            byte[] bytes=new byte[buffer_size];
            for(;;)
            {
              int count=is.read(bytes, 0, buffer_size);
              if(count==-1)
                  break;
              os.write(bytes, 0, count);
            }
        }
        catch(Exception ex){}
    }
}

By: Parmil.S & VkHooda

Lazy Adapter List View in android

public class LazyAdapter extends BaseAdapter {
       
        private Activity activity;
        private ArrayList<MessageData> _items;
        private LayoutInflater inflater=null;
        public ImageLoader imageLoader;
       // int count = 10;
       
        public LazyAdapter(Activity a,ArrayList<MessageData> _items) {
           
           
            activity = a;
            this._items=_items;
            inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            imageLoader=new ImageLoader(activity.getApplicationContext());
        }
   
        public int getCount() {
            return _items.size();
        }
        public Object getItem(int position) {
            return position;
        }
        public long getItemId(int position) {
            return position;
        }
        class ViewHolder{
           
            public TextView _nametitle,_timedesc;
            public ImageView _imageview;
        }
        public View getView(int position, View convertView, ViewGroup parent) {
           
           
            LayoutInflater inflater= activity.getLayoutInflater();
            View agntLocator=inflater.inflate(R.layout.msgdetailsrow, null);
           
            String _imgurl = _items.get(position)._image.toString().replaceAll(" ","%20");
            Log.d("ddddd","ddddddddd"+_imgurl);
             _img[position] = (ImageView)agntLocator.findViewById(R.id._msgrowimg);
              //_img[position].setImageBitmap(bmImg);
              imageLoader.DisplayImage(_imgurl, this.activity,  _img[position]);
              _img[position].measure(60,40);
             // _img[position].setOnClickListener(new Clickble());
            
            
              nametxt[position]=(TextView)agntLocator.findViewById(R.id._msgrowname);
              nametxt[position].setText(_items.get(position)._sendername);
            
              messagetxt[position]=(TextView)agntLocator.findViewById(R.id._msgrowmessge);
              messagetxt[position].setText(_items.get(position)._messdesc);
            
             timetxt[position]=(TextView)agntLocator.findViewById(R.id._msgrowtimefigure);
             timetxt[position].setText(_items.get(position)._time);
       
            
              return(agntLocator);
            }
        } 
}

By: Parmil.S & Vk Hooda

Handler Class which handle data coming from parsing in android

// Handler Class which handle data coming from parsing
   
    Handler _uicallback = new Handler(){
       
        public void handleMessage(Message msg) {
           
            switch(msg.what){
           
                case _updataResult :
           
                    if(messagesAL != null){
                       
                        if(messagesAL.size() > 0 ){
                            _img = new ImageView[messagesAL.size()];
                            nametxt=new TextView[messagesAL.size()];
                            timetxt=new TextView[messagesAL.size()];
                            messagetxt=new TextView[messagesAL.size()];
                            _progresssDialog.dismiss();
                           
        // Now taking one of List Adapter type for getting data in List View
                           
                    LazyAdapter _adaptor = new LazyAdapter(Messagelist.this,messagesAL);
                            setListAdapter(_adaptor);
                            //getListView().setOnScrollListener(Search.this);
                        }
                        else{
                           
                            _progresssDialog.dismiss();
                            Toast.makeText(Messagelist.this,"Error!!! Check File Size",Toast.LENGTH_LONG).show();
                        }
                    }
                    else{
                       
                        _progresssDialog.dismiss();
                        Toast.makeText(Messagelist.this,"Check Internet Connection...",Toast.LENGTH_LONG).show();
                    }
                   
            }
           
        };
       
    };
By: Parmil.S & Vk Hooda

Connection Establish Checking in android

// Connection Establish checking with connectivity manager
   
    private boolean checkInternetConnection() {

        ConnectivityManager conMgr = (ConnectivityManager) getSystemService (Context.CONNECTIVITY_SERVICE);

        if (conMgr.getActiveNetworkInfo() != null && conMgr.getActiveNetworkInfo().isAvailable() && conMgr.getActiveNetworkInfo().isConnected()) {

            return true;
         }
        else
        {
              return false;
        }

        }

By: Parmil.S & VkHooda

Update or use of thread in android

   
   
    // Checking for update result
private void getSearchedItems(){
       
        Thread _thread = new Thread(){
           
            public void run() {
           
                String _url="http://www.bestbusinessplaces.com/photoshare/showMessageXml.php?user_id=4";
                _conn = new Connection(_url);
                messagesAL =_conn.getmessagedata();
                Message _msg = new Message();
                _msg.what = _updataResult;
               
                Messagelist.this._uicallback.sendEmptyMessage(_msg.what);
               
            };
        };
        _thread.start();
    }
   
By: Parmil.S & VkHooda