Friday, January 11, 2019

Notification Example

Notification Example

This is an example Notification for Android Operating System.. It covers a two notification, one has sound, vibration and light effects. And another one is normal.

Following is the screen visual when activity starts.


Notification Exampe

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

Notify1.xml (Design)
       xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   
android:layout_width="match_parent"
   
android:layout_height="match_parent" android:orientation="vertical">

    <
LinearLayout
       
android:layout_width="match_parent"
       
android:layout_height="wrap_content"
       
android:orientation="horizontal">
        <
ImageView
           
android:id="@+id/img_back"
           
android:layout_width="wrap_content"
           
android:layout_height="wrap_content"
           
android:src="@drawable/ic_arrow_back"/>
        <
TextView
           
android:layout_width="match_parent"
           
android:layout_height="wrap_content"
           
android:text="Notification Example"
           
android:textSize="24sp"
           
android:textAlignment="center"/>


    </
LinearLayout>

   
<View
       
android:layout_width="match_parent"
       
android:layout_height="1dp"
       
android:background="#ffffff"
       
android:paddingBottom="50dp"></View>

    <
EditText
       
android:id="@+id/et_notify_name"
       
android:layout_width="match_parent"
       
android:layout_height="wrap_content"
       
android:hint="Enter Name"/>
    <
Button
       
android:id="@+id/btnNotify"
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:text="Notification (Vibrate, Light, Sound)"
       
android:layout_gravity="center_horizontal"/>
    <
Button
       
android:id="@+id/btnNotify2"
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:text="Notification"
       
android:layout_gravity="center_horizontal"/>
</
LinearLayout>
---------------------------------------------------------------------------------------------
Notify1.java

package in.co.mypractise.pranavdv.mypractise1;



import android.app.Activity;

import android.app.NotificationChannel;

import android.app.NotificationManager;

import android.app.PendingIntent;

import android.content.Intent;

import android.graphics.Color;

import android.media.RingtoneManager;

import android.os.Bundle;

import android.provider.CalendarContract;

import android.support.v4.app.NotificationCompat;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.ImageView;

import android.widget.Toast;



public class Notify1 extends Activity {

    Button btnNOTIFY, btn_NOTIFY2;

    ImageView img_BACK;

    EditText et_NAME;

    public static final String NOTIFICATION_CHANNEL_ID = "10001";



    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.notify1);

        img_BACK = findViewById(R.id.img_back);

        img_BACK.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View v) {

                finish();

            }

        });

        et_NAME = findViewById(R.id.et_notify_name);

        btnNOTIFY = findViewById(R.id.btnNotify);

        btnNOTIFY.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View v) {

                Toast.makeText(Notify1.this, "Button Click",

                        Toast.LENGTH_SHORT).show();



                // ------------ Notification Process-----------



                String notification_title = "My Practise1";

                String notification_message = "Message Will Appear Here";

                String message1 = et_NAME.getText().toString();

                String click_action = "Action";

                String from_user_id = "User ID";



                NotificationCompat.Builder mBuilder =

                        new NotificationCompat.Builder(getApplicationContext())

                                .setSmallIcon(R.drawable.ic_import_contacts_black_24dp)

                                .setContentTitle(notification_title)

                                .setContentText("Hi "+message1+" Thanks for using App");



                          //---- Notification Vibration, Lights, Sound---------                 

                        mBuilder.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 });

                        mBuilder.setLights(Color.GREEN,3000, 3000);

                        mBuilder.setSound(RingtoneManager.getDefaultUri

                                (RingtoneManager.TYPE_NOTIFICATION));


                Intent resultIntent = new Intent(click_action);

                resultIntent.putExtra("user_id", from_user_id);



                PendingIntent resultPendingIntent =

                        PendingIntent.getActivity(

                                getApplicationContext(),

                                0,

                                resultIntent,

                                PendingIntent.FLAG_UPDATE_CURRENT

                        );



                mBuilder.setContentIntent(resultPendingIntent);

                int mNotificationId = (int) System.currentTimeMillis();

                NotificationManager mNotifyMgr =

                        (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O)

                {

                    int importance = NotificationManager.IMPORTANCE_HIGH;

                    NotificationChannel notificationChannel = new NotificationChannel(

                            NOTIFICATION_CHANNEL_ID, "NOTIFICATION_CHANNEL_NAME",

                            importance);



                    mBuilder.setChannelId(NOTIFICATION_CHANNEL_ID);

                    mNotifyMgr.createNotificationChannel(notificationChannel);

                }

                mNotifyMgr.notify(mNotificationId, mBuilder.build());



                //---- Notification Process fiish---------

            }

        });



        btn_NOTIFY2 = findViewById(R.id.btnNotify2);

        btn_NOTIFY2.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View v) {

                String notification_title = "Title";

                String notification_message = "Message Will Appear Here";

                String message1 = et_NAME.getText().toString();

                NotificationCompat.Builder mBuilder =

                        new NotificationCompat.Builder(getApplicationContext())

                                .setSmallIcon(R.drawable.ic_import_contacts_black_24dp)

                                .setContentTitle(notification_title)

                                .setContentText("Hi "+message1+" Thanks for using App");




                int mNotificationId = (int) System.currentTimeMillis();

                NotificationManager mNotifyMgr =

                        (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

                



                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O)

                {

                    int importance = NotificationManager.IMPORTANCE_HIGH;

                    NotificationChannel notificationChannel = new NotificationChannel(

                            NOTIFICATION_CHANNEL_ID, "NOTIFICATION_CHANNEL_NAME",

                            importance);



                    mBuilder.setChannelId(NOTIFICATION_CHANNEL_ID);

                    mNotifyMgr.createNotificationChannel(notificationChannel);

                }

                mNotifyMgr.notify(mNotificationId, mBuilder.build());

            }

        });

    }

}


-----------------------------------------------------------------------------------------
Pranav Varma : mail at :  pranavdv@gmail.com | M : +91 98792 12359 | Website | YouTube

Wednesday, December 26, 2018

Check Box Example2

Check Box Example - 2

This is another example related to Checkbox. It covers a menu of a snacks bar. It also cover concept of popup message.


Select an item or multiple items then confirm it and you will get total amount as a result.


Check Video



Some Screen Visuals

  

 





Get Entire Code

Friday, February 22, 2013

Financial Report in Excel Part-1



Financial Report in Excel Part-1





With the video demonstration, u can learn how to convert last digit of a given number into zero. With the combination of  If Function, Value Function, Right Function, Ceiling Function and Floor Function, result generated.

=If (Value(Right(Reference,1))>=5, Ceiling(Reference,10), Floor(Reference,10) )

above combination used to generate the answer

Tuesday, August 28, 2012

Preference Controls : Android Training

Preference Control in Android

In Android with Shared Preferences we can set controls to build preference screens.
1. Check box Preference  2. Edit Tex Preference  3. List Preference
4. Ring Tone Reference

Here, example and codes given for Edit Tex Preference


- Package Explored Window

- Main Screen

- Preference Screen, when click to "click" button

- Dialogue Appear, when click to Name- Edit Text

- Message appear, when click to "ok" button


- Age Dialogue appear, when click to Age- Edit Text

- Message Appear, when click to "Ok" button

- Main Screen, When back from Preference Activity

- PreferenceNativeDemo Activity.java 


- SetPreference.java



- Manifest file


-pref1.xml - Generates Screen for Preferences


I hope this example will clear your concepts. If you like this codes, do not forget to give your comments. 

For any other query, you can mail : pranavdv@gmail.com

Monday, August 27, 2012

Date Picker in Android

Date Picker Concept in Android


Main Screen, When Activity launch. Current Date will Display in Text Box

Change Month, Date, Year and click to Set Date1 Button, 3 message will appear. 
First Message - "Date Set.."
Second Message - Age on base of date set. In following example, message will be "U R 6 years old"
Third Message - Birthday Reminder. Here in this example, 2 days before and 2 days after, set in coding




Now, Click on Second Button - "Set Date2", DatePicker Dialogue appear. Set the date 


After click to Set button of  DatePicker Dialogue, Message will appear which display Year and Month of Age. Also in second text box date will set


==================================================================

DatePicker1.java 


package co.PranavVarma;

import java.util.Calendar;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.text.method.DateTimeKeyListener;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.DatePicker.OnDateChangedListener;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;

public class DatePicker1 extends Activity{

public TextView tvhead, tvback, tvdtpick, tvdpd1, tvtime1, tvtime2;
public DatePicker dtpick1;
public DatePickerDialog dtpd1;
public Button btnsd1, btnsd2;
public int cyear, byear, cmonth,bmonth, cdate,bdate, hour1, min1;

public Calendar c = Calendar.getInstance();
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.datepicker1);


dtpick1 = (DatePicker) findViewById(R.id.dtpick1);
tvhead = (TextView) findViewById(R.id.txtHead);
tvback = (TextView) findViewById(R.id.txtBack);
tvdtpick = (TextView) findViewById(R.id.txtdtPickView);

tvhead.setText(getIntent().getExtras().getString("Head")+ " Concepts");
tvdtpick.setText("Date:" + dtpick1.getDayOfMonth() + " " + (dtpick1.getMonth()+1) + " "+ 
dtpick1.getYear());
tvback.setOnClickListener(new OnClickListener() {

public void onClick(View arg0) {
finish();

}
});
btnsd1 = (Button) findViewById(R.id.btnSetDate1);
btnsd1.setOnClickListener(new OnClickListener() {

public void onClick(View arg0) {
Toast t1 = Toast.makeText(DatePicker1.this, "Date Set..", 2000);
t1.setGravity(Gravity.CENTER_VERTICAL,0,0);
t1.show();
tvdtpick.setText("Date:" + dtpick1.getDayOfMonth() + " " + (dtpick1.getMonth()+1) + " "+ 
dtpick1.getYear());

cyear = c.get(Calendar.YEAR);
byear = dtpick1.getYear();
cmonth = c.get(Calendar.MONTH);
bmonth = dtpick1.getMonth();
cdate = c.get(Calendar.DATE);
bdate = dtpick1.getDayOfMonth();
int days = c.get(Calendar.DAY_OF_YEAR);



//Toast.makeText(DatePicker1.this, " "+days, 2000).show();

if(cmonth>bmonth)
Toast.makeText(DatePicker1.this, "U R " +(cyear-byear)+" years and "+(cmonth-bmonth) +" months Old", 3000).show();
else if(cmonth==bmonth)
Toast.makeText(DatePicker1.this, "U R " +(cyear-byear)+" years Old", 3000).show();
else
Toast.makeText(DatePicker1.this, "U R " +(cyear-byear-1)+" years and "+(12-bmonth+cmonth) +" months Old", 3000).show();


if(cmonth==bmonth)

if((cdate-bdate)<=2 && (cdate-bdate)>0)
//Toast.makeText(DatePicker1.this, "Birthday gone before " + (cdate-bdate)+" day", 2000).show();
Toast.makeText(DatePicker1.this, "Birthday After " + (cdate-bdate)+" day", 2000).show();
else if(cdate==bdate)
Toast.makeText(DatePicker1.this, "Today, is your birthday", 2000).show();
else if((bdate-cdate)<=2 && (bdate-cdate)>0)
//Toast.makeText(DatePicker1.this, "Birthday After " + (bdate-cdate)+" day", 2000).show();
Toast.makeText(DatePicker1.this, "Birthday gone before " + (bdate-cdate)+" day", 2000).show();
}
});

btnsd2 = (Button) findViewById(R.id.btnSetDate2);
tvdpd1 = (TextView) findViewById(R.id.txtdtPick2);
btnsd2.setOnClickListener(new OnClickListener() {

public void onClick(View arg0) {

new DatePickerDialog(DatePicker1.this, dateset, 
c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)
).show() ;
}
});


}
public DatePickerDialog.OnDateSetListener dateset = new DatePickerDialog.OnDateSetListener() {

@Override
public void onDateSet(DatePicker view, int year, int month, int day) {
/*cyear = year;
cmonth = month;
cdate = day;*/
tvdpd1.setText("Year: "+year + " Month : " + (month+1)  + " Date : " + day);

//----- same coding as above--------
// ------ To find the age and Birthday--------
cyear = c.get(Calendar.YEAR);
byear = year;
cmonth = c.get(Calendar.MONTH);
bmonth = month;
cdate = c.get(Calendar.DATE);
bdate = day;
int days = c.get(Calendar.DAY_OF_YEAR);



//Toast.makeText(DatePicker1.this, " "+days, 2000).show();

if(cmonth>bmonth)
Toast.makeText(DatePicker1.this, "U R " +(cyear-byear)+" years and "+(cmonth-bmonth) +" months Old", 3000).show();
else if(cmonth==bmonth)
Toast.makeText(DatePicker1.this, "U R " +(cyear-byear)+" years Old", 3000).show();
else
Toast.makeText(DatePicker1.this, "U R " +(cyear-byear-1)+" years and "+(12-bmonth+cmonth) +" months Old", 3000).show();


if(cmonth==bmonth)

if((cdate-bdate)<=2 && (cdate-bdate)>0)
//Toast.makeText(DatePicker1.this, "Birthday gone before " + (cdate-bdate)+" day", 2000).show();
Toast.makeText(DatePicker1.this, "Birthday After " + (cdate-bdate)+" day", 2000).show();
else if(cdate==bdate)
Toast.makeText(DatePicker1.this, "Today, is your birthday", 2000).show();
else if((bdate-cdate)<=2 && (bdate-cdate)>0)
//Toast.makeText(DatePicker1.this, "Birthday After " + (bdate-cdate)+" day", 2000).show();
Toast.makeText(DatePicker1.this, "Birthday gone before " + (bdate-cdate)+" day", 2000).show();

}


};

public TimePickerDialog.OnTimeSetListener timeset = new TimePickerDialog.OnTimeSetListener() {

public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
 
hour1 = hourOfDay;
min1 = minute;
tvtime2.setText("Time2 : "+ hour1+":"+min1);
}
};
}




=================================================================

if u like this article, do not forget to give feedback.
For any query, you can contact me through mail  pranavdv@gmail.com
Thanks from
Pranav


Notification Example

Notification Example This is an example Notification for Android Operating System.. It covers a two notification, one has sound, vibratio...