Sunday, December 16, 2018

Use of Logcat in Android Studio

The different Logcat methods are:
Log.v(); // Verbose
Log.d(); // Debug
Log.i(); // Info
Log.w(); // Warning
Log.e(); // Error
 
 
  • Log.e: This is for when bad stuff happens. Use this tag in places like inside a catch statement. You know that an error has occurred and therefore you're logging an error.
  • Log.w: Use this when you suspect something shady is going on. You may not be completely in full on error mode, but maybe you recovered from some unexpected behavior. Basically, use this to log stuff you didn't expect to happen but isn't necessarily an error. Kind of like a "hey, this happened, and it's weird, we should look into it."
  • Log.i: Use this to post useful information to the log. For example: that you have successfully connected to a server. Basically use it to report successes.
  • Log.d: Use this for debugging purposes. If you want to print out a bunch of messages so you can log the exact flow of your program, use this. If you want to keep a log of variable values, use this.
  • Log.v: Use this when you want to go absolutely nuts with your logging. If for some reason you've decided to log every little thing in a particular part of your app, use the Log.v tag.
And as a bonus...
  • Log.wtf: Use this when stuff goes absolutely, horribly, holy-crap wrong. You know those catch blocks where you're catching errors that you never should get...yeah, if you wanna log them use Log.wtf
 

Saturday, March 3, 2018

Use of Picasso and Glide Library

 Picasso lib : https://code.tutsplus.com/tutorials/android-sdk-working-with-picasso--cms-22149

Glide lib : https://github.com/codepath/android_guides/wiki/Displaying-Images-with-the-Glide-Library

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...