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);


            }
        });
    }

}

Sunday, December 11, 2016

Big number MOD function.


(A*B) % MOD = ((A % MOD) * (B % MOD)) % MOD
So
(A^n) % MOD = (((A ^ (n/2)) % MOD) * ((A ^ (n/2)) % MOD)) % MOD;




function is:

int cal(int pow, int val, int MOD) {
    if(pow == 0)
        return 1;
    int v = cal(pow/2, val, MOD);
    if(pow % 2 == 0)
        return (v*v) % MOD;
    else
        return (((v*val) % MOD) * v) % MOD;
}

Saturday, November 26, 2016

Best Sieve Technique

#include<iostream>
#include<cstdio>
#include<cmath>

int N = 5000, status[2501];
int main() {
    int i, j, sqrtN;
    for( i = 2; i <= N >> 1; i++ ) status[i] = 0;
    sqrtN = int( sqrt((double)N) ); // have to check primes up to (sqrt(N))
    for( i = 3; i <= sqrtN; i += 2 ) {
        if( status[i>>1] == 0 ) {
// so, i is a prime, so, discard all the multiples
// j = i * i, because it’s the first number to be colored
            for( j = i * i; j <= N; j += i + i )
                status[j>>1] = 1; // status of the multiple is 1
        }
    }
// print the primes
    printf("2 ");
    for( i = 3; i <= N; i += 2 ) {
        if( status[i>>1] == 0 )
            printf("%d ", i);
    }


}

by: Jane Alam Jan

Sieve of Eratosthenes

#include<iostream>
#include<cstdio>

int N=100000;
int status[100001];
int main(){
    int i,j;
    for(i=2; i<=N; i++) status[i]=0;
    for(i=3; i<=N; i+=2) {
        if(status[i] == 0) {
            for(j = 2* i; j<=N; j+=i) status[j] = 1;
        }
    }
    for( i=2; i<=N; i++) if(status[i]==0) printf("%d ", i);

    return 0;

}


Main Source : Jane Alam Jan

int N = 5000;int status[5001];// status[i] = 0, if i is prime
// status[i] = 1, if i is not a prime
int main() {int i, j;// initially we think that all are primesfor( i = 2; i <= N; i++ )
status[i] = 0;
for( i = 3; i <= N; i += 2 ) {if( status[i] == 0 ) {// so, i is a prime, so, discard all the multiples
// 3 * i is odd, since i is odd. And j += 2 * i, so, the next odd
// number which is multiple of i will be found
for( j = 3 * i; j <= N; j += 2 * i )
status[j] = 1;
// status of the multiple is 1}
}
// print the primesprintf("2 ");for( i = 3; i <= N; i += 2 ) {if( status[i] == 0 ) {// so, i is primeprintf("%d ", i);
}
}
return 0;
}
  


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