Tuesday, December 12, 2017

I love programming

Thanks my programming . I solve this problem. Now I can calculate the time difference .

I want to remember this code. I am really really excited now.

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


button1 = (Button) findViewById(R.id.setalarm);
tp = (TimePicker) findViewById(R.id.tp);

// button click to get time from time-picker
button1.setOnClickListener(new View.OnClickListener() {
    @Override    public void onClick(View view) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(
                calendar.get(Calendar.YEAR),
                calendar.get(Calendar.MONTH),
                calendar.get(Calendar.DAY_OF_MONTH),
                tp.getHour(),
                tp.getMinute(),
                0
        );



        Intent intent = new Intent(MainActivity.this, Notification_receiver.class);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 100, intent, PendingIntent.FLAG_UPDATE_CURRENT);

        // this time is for reminder--- 
       long value = calendar.getTimeInMillis();
        System.out.println(value);

        // to get present time--- 
        java.util.Calendar time = java.util.Calendar.getInstance();
        long present_time = time.getTimeInMillis();
        System.out.println(present_time);


        long difference = value - present_time;
        System.out.println(difference);
 
------------------------------------------------------------------------------------------------------------------------------------------------------- 

Sunday, December 10, 2017

Full reference : Snackbar Details

Code for snackbar :

Button button = (Button) findViewById(R.id.button);

button.setOnClickListener(new View.OnClickListener() {
    @Override    public void onClick(View view) {
        Snackbar.make(view, "text", Snackbar.LENGTH_LONG).setAction("action", null).show();

    }
});

Saturday, December 9, 2017

ArrayList in java

Simple things for ArrayList:

 // declare ArrayList ArrayList<String> myList = new ArrayList<>(10);
 ArrayList<Integer> myListI = new ArrayList<>(1);
// myList.add("hello what is your name?\n I like you"); // Adding data myListI.add(1);
 myListI.add(2);
 myListI.add(3);
 

 for(Integer i : myListI) {
     System.out.println(i);
 }

 System.out.println(myListI);



All about ArrayList

Simple Notification for android

---This code will generate simple notification through a button click.--

// build the content of  notification

NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());
builder.setContentTitle("Normal Notification");
builder.setContentText("This a normal notification");
builder.setTicker("This is a ticker");
builder.setSmallIcon(R.mipmap.ic_launcher);
builder.setAutoCancel(true);

// add notification sound

Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Uri uri1= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
builder.setSound(uri);
// notification through notification manager

Notification notification = builder.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(1234, notification);



Friday, December 8, 2017

Android Notification

package com.example.tamzid.notification;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    Button normal_notification;

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

        normal_notification = (Button) findViewById(R.id.normal_notification);

        normal_notification.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {

                // build the content of notification
                NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());
                builder.setContentTitle("Normal Notification");
                builder.setContentText("This a normal notification");
                builder.setTicker("This is a ticker");
                builder.setSmallIcon(R.mipmap.settings);
                //builder.setSound()                builder.setAutoCancel(true);

                // intent                Intent i = new Intent(MainActivity.this, Acitvity_B.class);

                // COVERT   the intent to pending intent
                TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext());
                stackBuilder.addParentStack(Acitvity_B.class);
                stackBuilder.addNextIntent(i);
                PendingIntent pi_main = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

                builder.setContentIntent( pi_main);

                //notification button
                Intent setting = new Intent(MainActivity.this, Acitvity_B.class);

                TaskStackBuilder stackBuilder_setting = TaskStackBuilder.create(getApplicationContext());
                stackBuilder_setting.addParentStack(Acitvity_B.class);
                stackBuilder_setting.addNextIntent(setting);
                PendingIntent pi_setting = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

                //notification button setter                builder.addAction(R.mipmap.settings,"setting", pi_setting);
                builder.addAction(R.mipmap.ic_launcher, "help", pi_main);
                builder.setAutoCancel(true);



                // notification through notification manager
                Notification notification = builder.build();
                NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                notificationManager.notify(1234, notification);


            }
        });
    }

}

Speedup Android Studio

Go to Help ->Edit Custom VM Options, and chnge this 4 setting. After that close your Android Studio. This settings are for 8gb of ram pc...