Monday, 3 July 2017

Firebase Cloud Messaging (FCM)

 Firebase Cloud Messaging (FCM)

create a new project

----------------------------MainActivity.java----------------------------- 

package httpbcom.firebasenewdemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

----------------------------activity_main.xml-----------------------------

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 xmlns:app="http://schemas.android.com/apk/res-auto" 
 xmlns:tools="http://schemas.android.com/tools" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" 
 tools:context="httpbcom.firebasenewdemo.MainActivity">

    <TextView  
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:text="Hello World!"/>
</LinearLayout>
yello line you will be added to your new porject

----------------------------AndroidManifest.xml----------------------------

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
 package="httpbcom.firebasenewdemo">
    <uses-permission android:name="android.permission.INTERNET" />
    <application 
 android:allowBackup="true" 
 android:icon="@mipmap/ic_launcher" 
 android:label="@string/app_name" 
 android:roundIcon="@mipmap/ic_launcher_round" 
 android:supportsRtl="true" 
 android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service android:name=".MyFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

        <!--service to create firebase instance ID(Device Token)--> 
 <service android:name=".MyFirebaseInstanceIDService">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
            </intent-filter>
        </service>
    </application>

</manifest>
 
 
 
 
 
 
 
 
 
create a new class MyFirebaseInstanceIDService.class

 
 
 
 

----------------------------MyFirebaseInstanceIDService.class-------------------

 
 
 
 package httpbcom.firebasenewdemo;

import android.util.Log;

import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;

/** * Created by munnu on 27/06/2017. */
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {

    private static final String TAG = "MyFirebaseIIDService";

    @Override    public void onTokenRefresh() {
        //Getting registration token 
 String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        //Displaying token on logcat 
 Log.e(TAG, "Refreshed token: " + refreshedToken);
    }

    private void sendRegistrationToServer(String token) {
        //You can implement this method to store the token on your server 
 //Not required for current project    }
}
 
 
 
 
create a new class MyFirebaseMessagingService.class

----------------------------MyFirebaseMessagingService.class-------------------

  package httpbcom.firebasenewdemo;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;

/** * Created by munnu on 27/06/2017. */
public class MyFirebaseMessagingService extends FirebaseMessagingService {

    private static final String TAG = "MyFirebaseMsgService";

    @Override    public void onMessageReceived(RemoteMessage remoteMessage) {

        //Displaying data in log 
 Log.d(TAG, "From: " + remoteMessage.getFrom());
        Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());

        //Calling method to generate notification 
 sendNotification(remoteMessage.getNotification().getBody());
    }

    //This method is only for generating local notification with push notification data(titlenmessage) 
 private void sendNotification(String messageBody) {
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
                PendingIntent.FLAG_ONE_SHOT);
        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("Firebase Push Notification")
                .setContentText(messageBody)
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);
 NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
 notificationManager.notify(0, notificationBuilder.build());
    }
}
 
 

----------------------------build.gradle(project:FireBaseDemo)------------------------

 // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.2' 
 classpath 'com.google.gms:google-services:3.0.0' 
 // NOTE: Do not place your application dependencies here; they belong 
 // in the individual module build.gradle files    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
 
  

----------------------------build.gradle(Module:FireBaseDemo)------------------------

apply plugin: 'com.android.application'
android {
    compileSdkVersion 25 
 buildToolsVersion "25.0.3" 
 defaultConfig {
 applicationId "httpbcom.firebasenewdemo" 
 minSdkVersion 15 
 targetSdkVersion 25 
 versionCode 1 
 versionName "1.0" 
 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"    }
    buildTypes {
        release {
            minifyEnabled false 
 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'    })
    compile 'com.android.support:appcompat-v7:25.3.1' 
 compile 'com.android.support.constraint:constraint-layout:1.0.2' 
 testCompile 'junit:junit:4.12'
     compile 'com.google.firebase:firebase-messaging:9.6.0'
}

apply plugin: 'com.google.gms.google-services'
 
 
 

--------------------------And then you go this link-----------------------

     https://console.firebase.google.com/  


Enter your application name and select your country. then click on create project

  Now you will see a screen like this

 
 
  1. then click on "add Firebase to your Android app" 
  2.  
  3. .Now put 
    1. Package name  
    2. App nickname (optional)
    3. Debug signing certificate SHA-1 (optional)  
 
 
 
 
 
  Copy and paste the google-services.jFirebase Cloud Messaging(FCM)son file into the application root directory.
 
 and go to project and paste them into app folder
 
 
 
                                                       
 

Recyclerview Example

                                        Recyclerview Example



-----------MainActivity.java----------------------- 
package com.abc.jsonrecycle;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private CardViewAdapter cardViewAdapter;
    private List<MainModel> cardList = new ArrayList<>();
    int images[] = new int[]{R.drawable.newimage, R.drawable.virat, R.drawable.image, R.drawable.image1,R.drawable.first};
    int images1[] = new int[]{R.drawable.newimage, R.drawable.virat, R.drawable.image, R.drawable.image1,R.drawable.team};

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        recyclerView = (RecyclerView) findViewById(R.id.RecyclerView);



        cardList.add(new MainModel("Sohel", "10 march 2017","Team India", images[4], images1[4]));
        cardList.add(new MainModel("Dollop", "11 march 2017", "Team India", images[1], images1[4]));
        cardList.add(new MainModel("Meenakshi", "12 march 2017", "Team India", images[2], images1[4]));
        cardList.add(new MainModel("Shirsh", "13 march 2017", "Team India",  images[3], images1[4]));

        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
        recyclerView.setLayoutManager(layoutManager);
        cardViewAdapter = new CardViewAdapter(cardList);
        recyclerView.setAdapter(cardViewAdapter);
    }
}


---------mainactivity.xml----------------------------
<?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 xmlns:tools="http://schemas.android.com/tools" 
 android:id="@+id/activity_main" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent">
    <android.support.v7.widget.RecyclerView 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:id="@+id/RecyclerView">
    </android.support.v7.widget.RecyclerView>
</RelativeLayout>



-------CalenderCardViewAdapter----------------------------
package com.abc.jsonrecycle;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/** * Created by munnu on 09/03/2017. */
public class CardViewAdapter extends RecyclerView.Adapter<CardViewAdapter.MyViewHolder> {


    List<MainModel> clickCategoryList;
    Context context;

    public CardViewAdapter(List<MainModel> clickCategoryList) {
        this.clickCategoryList = clickCategoryList;
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        TextView nameTextView, Date, Text;
        ImageView imageView, imageView1;

        public MyViewHolder(View view) {
            super(view);

            nameTextView = (TextView) view.findViewById(R.id.nameTextView);
            Date = (TextView) view.findViewById(R.id.Date);
            Text = (TextView) view.findViewById(R.id.Text);
            imageView = (ImageView) view.findViewById(R.id.imageView);
            imageView1 = (ImageView) view.findViewById(R.id.imageView1);


        }

    }

    @Override    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        context = parent.getContext();
        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.cardviewadapter, parent, false);

        return new MyViewHolder(itemView);
    }

    @Override    public void onBindViewHolder(MyViewHolder holder, final int position) {
        final MainModel clickCategoryListObject = clickCategoryList.get(position);
        holder.nameTextView.setText(clickCategoryListObject.getName());
        holder.Date.setText(clickCategoryListObject.getText());
        holder.Text.setText(clickCategoryListObject.getText());
        holder.imageView.setImageResource(clickCategoryListObject.getImage());

          holder.imageView1.setImageResource(clickCategoryListObject.getImage1());

    }


    @Override    public int getItemCount() {
        return clickCategoryList.size();
    }
}

 ------------------------cadrviewadapter.xml---------------------
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 xmlns:app="http://schemas.android.com/apk/res-auto" 
 android:layout_width="match_parent" 
 android:layout_height="300dp" 
 android:orientation="vertical">

    <android.support.v7.widget.CardView 
 android:id="@+id/CardView" 
 android:layout_width="match_parent" 
 android:layout_height="300dp" 
 android:layout_alignParentLeft="true" 
 android:layout_alignParentStart="true" 
 android:layout_alignParentTop="true" 
 android:layout_margin="10dp" 
 android:elevation="10dp" 
 app:cardCornerRadius="10dp">

        <RelativeLayout 
 android:layout_width="match_parent" 
 android:layout_height="match_parent">

            <ImageView 
 android:id="@+id/imageView" 
 android:layout_width="60dp" 
 android:layout_height="60dp" 
 android:layout_marginLeft="5dp" 
 android:layout_marginTop="10dp" 
 
 android:scaleType="fitXY" 
 android:src="@drawable/image" />

            <LinearLayout 
 android:layout_width="match_parent" 
 android:layout_height="60dp" 
 android:layout_toRightOf="@+id/imageView" 
 android:layout_marginTop="10dp" 
 android:layout_marginLeft="5dp" 
 android:gravity="center_vertical" 
 android:orientation="vertical">

                <TextView 
 android:id="@+id/nameTextView" 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:text="Name" 
 android:textColor="@color/colorPrimary" 
 android:textSize="20sp" 
 android:textStyle="bold" />

                <TextView 
 android:id="@+id/Date" 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:text="Date" 
 android:textColor="@color/colorAccent" 
 android:textSize="16sp" 
 android:textStyle="normal" />
 </LinearLayout>
 <TextView 
 android:id="@+id/Text" 
 
 android:layout_width="match_parent"  
 android:layout_height="wrap_content" 
 android:layout_below="@+id/imageView" 
 android:layout_marginLeft="5dp" 
 android:text="M.S.Dhoni" 
 android:textColor="@color/colorPrimary" 
 android:textSize="16sp" />

            <ImageView 
 android:id="@+id/imageView1" 
 android:layout_marginTop="5dp" 
 android:layout_marginBottom="5dp" 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:layout_below="@+id/Text" 
 android:src="@drawable/newimage" />

        </RelativeLayout>
    </android.support.v7.widget.CardView>
</RelativeLayout>

---------------build.gradle(dependency)-----------------------


compile 'com.android.support:appcompat-v7:25.0.1'testCompile 'junit:junit:4.12'compile 'com.android.support:design:25.0.1'compile 'com.android.support:recyclerview-v7:25.0.1'compile 'com.android.support:cardview-v7:25.0.1'

Friday, 30 June 2017

Splash Screen

Android is the mobile operating system developed by Google. Essentially, Google produces the software that runs almost every other mobile phone besides Apple’s iPhone. There are also some popular Android tablets as well. Android is a Linux-based software system, and similar to Linux, is free and open source software. This means that other companies can use the Android operating system developed by Google and use it in their mobile devices (more on that later). The distinguishing factor of this brand is a kernel. Android hosts a central core, which essentially is a strip code that helps the software operate.
Android development is the great mobile developing language this time for those person who will be  interested for software development.



1) Android Splash Screen Code

1)first you Start a new project

-------------------------------------------------MainActivity.java------------------------------------------------



package com.dollop.bankapp.activity;

import android.os.Bundle;
import android.os.Handler;

import com.dollop.bankapp.R;
import com.dollop.bankapp.shirsh.S;

/** * Created by shirsh on 5/17/2017. */
public class SplashActivity extends BaseActivity {

    @Override    protected int getContentResId() {
        return R.layout.main_activity;
    }

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        new Handler().postDelayed(new Runnable() {
            @Override            public void run() {
                S.I(SplashActivity.this, StartUpPageActivity.class, null);
                finish();
            }
        }, 2000);
    }
}



-------------------------------------------------main_activity.xml--------------------------------------------------
 
 
 
 
<?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent">

    <LinearLayout 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" 
 android:gravity="center" 
 android:orientation="vertical">

       
      <TextView
             android:layout_width="match_parent" 
             android:layout_height="wrap_parent"
             android:gravity="center" 
             android:text="Hello"/>
    </LinearLayout>

</RelativeLayout>

AutoComplete Address (Updated)

-------------------------------------Activity---------------------------------- package placeautocomplete.iteritory.com; import androi...