Search Google

Friday, 27 February 2015

all about android

 best code http://sunil-android.blogspot.in/
 
 
 

Android ViewPager Gallery Images and Texts Tutorial

 PHONE GAP BEST EXAMPLE http://androidshivendra.blogspot.in/2013/12/simple-android-phonegap-example.html

--------------------------------------------------------------------------------- 

Implemeting A Simple Splash Screen

public class SplashScreenActivity extends Activity {
 
 // Show the Splash Screen for 3secs(3000ms)
 long START_UP_DELAY = 3000L;
  
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.splashscreen);
   
   
  // Add delay so that Splash Screen is displayed for 3secs
  new Handler().postDelayed(new Runnable() {
   @Override
   public void run() {
 
    Intent loginPage = new Intent(SplashScreenActivity.this, LoginActivity.class);
    startActivity(loginPage);
   }
  }, START_UP_DELAY);
 }
  
 // Override the onPause method to kill this Activity, so that pressing the back button doesn't bring up this screen.
 @Override
 protected void onPause() {
  // TODO Auto-generated method stub
  super.onPause();
  this.finish();
 }
}

The corresponding XML file for the UI :

splashscreen.xml
?
1
2
3
4
5
<relativelayout android:layout_height="match_parent" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android">
 
    <imageview android:id="@+id/splashImage" android:layout_centerhorizontal="true" android:layout_centervertical="true" android:layout_height="fill_parent" android:layout_width="fill_parent" android:src="@drawable/splashscreen">
 

Option Menu:
Option Menu is a drop down menu containing   options, and appears when a users clicks on Menu button.
For Ex:
 

         

Context Menu 

A context menu provides actions that affect a specific item or context frame in the UI.
Context Menu appears when user long press on a View like ListView, GridView etc. ALERT

 

ViewPagerImageTutorial ScreenShot

 ---------------------------------------------

Android TabWidget Example

Android TabHost  provides a nice way to present multiple thing on a Single Screen. These  things are presented by Tabs.

In order to use tabs we need to set 2 things to Tab
1: Tab Indicator : Text to show on Tab,  done by  setIndicator("Tab Name");
2: TAB Content: The activity that will be opened when user selects/clicks particular tab, done by  setContent(activityObject);

main.xml


Android TabHost

<?xml version="1.0" encoding="utf-8"?>

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
          android:id="@android:id/tabhost">
        
        <LinearLayout
                android:id="@+id/LinearLayout01"
                android:orientation="vertical"
                android:layout_height="fill_parent"
                android:layout_width="fill_parent">
               
                <TabWidget
                    android:id="@android:id/tabs"
                    android:layout_height="wrap_content"
                    android:layout_width="fill_parent">
                </TabWidget>
               
                <FrameLayout
                    android:id="@android:id/tabcontent"
                    android:layout_height="fill_parent"
                     android:layout_width="fill_parent">
                </FrameLayout>
               
        </LinearLayout>

</TabHost>


TabActivity.java


public class MainActivity extends TabActivity
{
            /** Called when the activity is first created. */
            @Override
            public void onCreate(Bundle savedInstanceState)
            {
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.main);

                    // create the TabHost that will contain the Tabs
                    TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);


                    TabSpec tab1 = tabHost.newTabSpec("First Tab");
                    TabSpec tab2 = tabHost.newTabSpec("Second Tab");
                    TabSpec tab3 = tabHost.newTabSpec("Third tab");

                   // Set the Tab name and Activity

                   // that will be opened when particular Tab will be selected
                    tab1.setIndicator("Tab1");
                    tab1.setContent(new Intent(this,Tab1Activity.class));
                   
                    tab2.setIndicator("Tab2");
                    tab2.setContent(new Intent(this,Tab2Activity.class));

                    tab3.setIndicator("Tab3");
                    tab3.setContent(new Intent(this,Tab3Activity.class));
                   
                    /** Add the tabs  to the TabHost to display. */
                    tabHost.addTab(tab1);
                    tabHost.addTab(tab2);
                    tabHost.addTab(tab3);

            }
}


Tab1Activity.java

public class Tab1Activity  extends Activity
{
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
           
            TextView  tv=new TextView(this);
            tv.setTextSize(25);
            tv.setGravity(Gravity.CENTER_VERTICAL);
            tv.setText("This Is Tab1 Activity");
           
            setContentView(tv);
        }
}

Tab2Activity.java

public class Tab2Activity  extends Activity
{
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
           
            TextView  tv=new TextView(this);
            tv.setTextSize(25);
            tv.setGravity(Gravity.CENTER_VERTICAL);
            tv.setText("This Is Tab2 Activity");
           
            setContentView(tv);
        }
}

Tab3Activity.java

public class Tab3Activity  extends Activity
{
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
           
            TextView  tv=new TextView(this);
            tv.setTextSize(25);
            tv.setGravity(Gravity.CENTER_VERTICAL);
            tv.setText("This Is Tab3 Activity");
           
            setContentView(tv);
        }
}




Android TabHost
 
 
---------------------------------------------------------------------------------------------
 

Android Paypal Gateway Example | Paypal demo in android | Pay inside App using Paypal and Credit card


Hi Friends, in past we were using third party library for Paypal payment but now Paypal provide us their own library for payment so it is now much secure and easy to implement in our application. Below are the important step to do -



1)First go through Paypal Developer web site and create an application.

2)Now open your manifest file and give the below permissions-

<uses-permission android:name="android.permission.INTERNET" />

     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


3)And some required Activity and Services-
<service
            android:name="com.paypal.android.sdk.payments.PayPalService"
            android:exported="false" />
        <activity android:name="com.paypal.android.sdk.payments.PaymentActivity" />
        <activity android:name="com.paypal.android.sdk.payments.LoginActivity" />
        <activity android:name="com.paypal.android.sdk.payments.PaymentMethodActivity" />
        <activity android:name="com.paypal.android.sdk.payments.PaymentConfirmActivity" />
        <activity android:name="com.paypal.android.sdk.payments.PayPalFuturePaymentActivity" />
        <activity android:name="com.paypal.android.sdk.payments.FuturePaymentConsentActivity" />
        <activity android:name="com.paypal.android.sdk.payments.FuturePaymentInfoActivity" />
        <activity
            android:name="io.card.payment.CardIOActivity"
            android:configChanges="keyboardHidden|orientation" />
        <activity android:name="io.card.payment.DataEntryActivity" />
4)Open your Activity class and set Configuration for your app-
//set the environment for production/sandbox/no netowrk
       private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_PRODUCTION;
5)Now set client id from the Paypal developer account-
     private static final String CONFIG_CLIENT_ID = "PUT YOUR CLIENT ID";
6)Inside onCreate method call the Paypal service-
Intent intent = new Intent(this, PayPalService.class);
        intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
        startService(intent);


7)Now you are ready to make a payment just on button press call the Payment Activity-
PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal(1),"USD", "androidhub4you.com",
                                 PayPalPayment.PAYMENT_INTENT_SALE);
                             Intent intent = new Intent(MainActivity.this, PaymentActivity.class);
                             intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);

                             startActivityForResult(intent, REQUEST_PAYPAL_PAYMENT);    


8)And finally from the onActivityResult get the payment response-
  @Override
           protected void onActivityResult(int requestCode, int resultCode, Intent data) {
               if (requestCode == REQUEST_PAYPAL_PAYMENT) {
                   if (resultCode == Activity.RESULT_OK) {
                       PaymentConfirmation confirm = data
                               .getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
                       if (confirm != null) {
                           try {
                           System.out.println("Responseeee"+confirm);
                               Log.i("paymentExample", confirm.toJSONObject().toString());
                            
                               JSONObject jsonObj=new JSONObject(confirm.toJSONObject().toString());
                              
                               String paymentId=jsonObj.getJSONObject("response").getString("id");
                               System.out.println("payment id:-=="+paymentId);
                               Toast.makeText(getApplicationContext(), paymentId, Toast.LENGTH_LONG).show(); 
                           } catch (JSONException e) {
                               Log.e("paymentExample", "an extremely unlikely failure occurred: ", e);
                           }
                       }
                   } else if (resultCode == Activity.RESULT_CANCELED) {
                       Log.i("paymentExample", "The user canceled.");
                   } else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
                       Log.i("paymentExample", "An invalid Payment was submitted. Please see the docs.");
                   }
               }
              
               
         }

For any query or suggestion please post your feedback.
Thanks,


Read more: http://www.androidhub4you.com/2014/07/android-paypal-gateway-example-paypal.
 
------------------------------------------------------
 
Frame Layout means each view comes in form of frame like a view upon another view. This layout helps us if we want to display any text or image on any background image.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >
    <TextView
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="25sp"
        android:layout_marginTop="5dp"
        android:layout_centerHorizontal="true"
        android:text="@string/hello_world" />
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/text1"
        android:layout_marginTop="15dp" >
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:scaleType="fitXY"
            android:layout_gravity="center"
            android:src="@drawable/desert" />
       
        <ImageView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_gravity="center"
            android:src="@drawable/ic_launcher" />
        <TextView
            android:id="@+id/text2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:textColor="#CCCC00"
            android:textSize="35sp"
            android:text="@string/app_name" />
    </FrameLayout>

</RelativeLayout>

No comments:

Post a Comment