Sunday, April 7, 2019

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.

# custom Android Studio VM options, see https://developer.android.com/studio/intro/studio-config.html

-Xmx2g
-Xms1G
-XX:MaxPermSize=1G
-XX:ReservedCodeCacheSize=512m

Wednesday, March 27, 2019

Input multiple data into Realtime Database of Firebase


Explanation of adding unique key and how to add multiple data without updatingexisting data.


if database reference child is fixed string, new value will not add. just it will update the previous value. for example :
DatabaseReference myRef = FirebaseDatabase.getInstance().getReference(); String mText = // get data from editText or set your own custom data
now if I insert data like this:
myRef.child("abc").child("cba").setValue(mText);
every time I insert data it will update my previous data. It will not add new data. Because my reference is fixed here(myRef.child("abc").child("cba") // this one, which is always fixed).
Now change the the value of child "cba" to a random or dynamic value which will not fix. For example:
Random rand = new Random(); // Obtain a number between [0 - 49]. int n = rand.nextInt(50); myRef.child("abc").child(String.valueOf(n)).setValue(mText);
In this case it will add a new value instead of updating. because this time reference is not fixed here. it is dynamic. push() method exactly do the same thing. it generates random key to maintain unique reference.

A reference link for CRUD operation in Realtime Database : Firebase CRUD

An Android project with CRUD operation example : Project Link

Sunday, March 24, 2019

Code Hack : Get IP Address

Give Permission from Manifest:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

Get IP Address:

WifiManager wm = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());

Saturday, March 23, 2019

BFS


// Java program to print BFS traversal from a given source vertex.

// BFS(int s) traverses vertices reachable from s.

import java.io.*;

import java.util.*;


// This class represents a directed graph using adjacency list

// representation

class Graph

{

 private int V; // No. of vertices

 private LinkedList&lt;Integer&gt; adj[]; //Adjacency Lists


 // Constructor

 Graph(int v)

 {

  V = v;

  adj = new LinkedList[v];

  for (int i=0; i&lt;v; ++i)

   adj[i] = new LinkedList();

 }


 // Function to add an edge into the graph

 void addEdge(int v,int w)

 {

  adj[v].add(w);

 }


 // prints BFS traversal from a given source s

 void BFS(int s)

 {

  // Mark all the vertices as not visited(By default

  // set as false)

  boolean visited[] = new boolean[V];


  // Create a queue for BFS

  LinkedList&lt;Integer&gt; queue = new LinkedList&lt;Integer&gt;();


  // Mark the current node as visited and enqueue it

  visited[s]=true;

  queue.add(s);


  while (queue.size() != 0)

  {

   // Dequeue a vertex from queue and print it

   s = queue.poll();

   System.out.print(s+" ");


   // Get all adjacent vertices of the dequeued vertex s

   // If a adjacent has not been visited, then mark it

   // visited and enqueue it

   Iterator&lt;Integer&gt; i = adj[s].listIterator();

   while (i.hasNext())

   {

    int n = i.next();

    if (!visited[n])

    {

     visited[n] = true;

     queue.add(n);

    }

   }

  }

 }


 // Driver method to

 public static void main(String args[])

 {

  Graph g = new Graph(4);


  g.addEdge(0, 1);

  g.addEdge(0, 2);

  g.addEdge(1, 2);

  g.addEdge(2, 0);

  g.addEdge(2, 3);

  g.addEdge(3, 3);


  System.out.println("Following is Breadth First Traversal "+

      "(starting from vertex 2)");


  g.BFS(2);

 }

}

// This code is contributed by Aakash Hasija



Access Activity class public fields from Non-Activity Class

Code hack :


public class NonActivityClass {
    //can I access the variables and methods from here

    MainActivity mainActivity;

    public NonActivityClass(MainActivity activity) {
        mainActivity = activity;
    }

    public void doSomething() {
        String name = mainActivity.name;
    }

}





Wednesday, February 20, 2019

Understand How Progress Bar Work

MainActiviy.java code is here:


package com.example.arafat.progressbar;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;

public class MainActivity extends AppCompatActivity {

    private ProgressBar progressBar;
    private int status = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        progressBar = findViewById(R.id.progress_horizontal);
        progressBar.setProgress(0);
        progressBar.setMax(5);
        Button tabButton = findViewById(R.id.tab_btn);

        tabButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                status++;
                progressBar.setProgress(status);
            }
        });
    }
}




activity_main.xml code is here :

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <ProgressBar
        android:id="@+id/progress_horizontal"
        style="@android:style/Widget.ProgressBar.Horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp" />

    <Button
        android:id="@+id/tab_btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/progress_horizontal"
        android:layout_marginTop="64dp"
        android:text="tab" />

</RelativeLayout>

Friday, January 25, 2019

Different Frameworks and Libraries of Android

The main aim of frameworks is to increase productivity by reducing efforts which eventually saves lot of time for developers to resolve any other important issues in the app or game. These frameworks provides inbuilt tools for developers to work instantly on difficult and lengthy part of coding.


Some Popular Frameworks List:

  1. Corona SDK
  2. Phonegap
  3. Xamarin
  4. Sencha Touch 2
  5. Appcelerator
  6. Basic4Android
  7. JQuery Mobile
  8. Dojo Mobile
  9. Sproutcore
  10. Theappbuilder
  11. DHTMLX Touch
  12. Mo Sync SDK

Tuesday, January 22, 2019

Fixed nav-bar section

html code :
<div id="footer">    <hr>    <p>Designed by Arafat. No right reserved</p>    <a style="color: white; text-decoration: none; cursor: pointer; font-weight: bold;" href="dashboard.php">        <p> There is no God none but Allah</p>    </a>    <hr></div>

css code:

#footer {    padding: 10px;    border-top: 1px solid black;    color: #eeeeee;    background-color: #211f22;    text-align: center;    position: fixed;    left: 0;    bottom: 0;    width: 100%;}
try this for fixed footer section 

Tuesday, January 15, 2019

Android Library List

implementation 'com.github.rey5137:material:1.2.5'
// for paper library
implementation 'io.paperdb:paperdb:2.6'

Circular image

Github Repository

xml attribute :

<de.hdodenhof.circleimageview.CircleImageView
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/profile_image"
    android:layout_width="96dp"
    android:layout_height="96dp"
    android:src="@drawable/profile"
    app:civ_border_width="2dp"
    app:civ_border_color="#FF000000"/>
Dependency : implementation 'de.hdodenhof:circleimageview:2.2.0'


 Picasso

Library Link 

Dependency :
implementation 'com.squareup.picasso:picasso:2.71828'
if you get any error user this one
implementation 'com.squareup.picasso:picasso:2.5.2'

 Image cropper Library:


Library Link

Dependency :  
implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.+' (this one is stable)

// android arsenal link : https://android-arsenal.com/details/1/4136
implementation 'com.cepheuen.elegant-number-button:lib:1.0.2'
// from github

Weather api Library:
dependency : 
compile 'com.loopj.android:android-async-http:1.4.9'

Link : Weather api details

Android Asynchronous Http Client

Library address 

dependency :

compile 'com.loopj.android:android-async-http:1.4.9'
 

Friday, January 11, 2019

Big O notation

Different time complexity of some common algorithms ...

1. O(1)

O(1) describes an algorithm that will always execute in the same time (or space) regardless of the size of the input data set.

bool IsFirstElementNull(IList<string> elements)
{
    return elements[0] == null;
}
 

2. O(N)

O(N) describes an algorithm whose performance will grow linearly and in direct proportion to the size of the input data set. The example below also demonstrates how Big O favours the worst-case performance scenario; a matching string could be found during any iteration of the for loop and the function would return early, but Big O notation will always assume the upper limit where the algorithm will perform the maximum number of iterations.

bool ContainsValue(IList<string> elements, string value)
{
    foreach (var element in elements)
    {
        if (element == value) return true;
    }

    return false;
}

 


3. O(N2)

O(N2) represents an algorithm whose performance is directly proportional to the square of the size of the input data set. This is common with algorithms that involve nested iterations over the data set. Deeper nested iterations will result in O(N3), O(N4) etc.

bool ContainsDuplicates(IList<string> elements)
{
    for (var outer = 0; outer < elements.Count; outer++)
    {
        for (var inner = 0; inner < elements.Count; inner++)
        {
            // Don't compare with self
            if (outer == inner) continue;

            if (elements[outer] == elements[inner]) return true;
        }
    }

    return false;
}
 

4. O(2N)

O(2N) denotes an algorithm whose growth doubles with each additon to the input data set. The growth curve of an O(2N) function is exponential - starting off very shallow, then rising meteorically. An example of an O(2N) function is the recursive calculation of Fibonacci numbers:

int Fibonacci(int number)
{
    if (number <= 1) return number;

    return Fibonacci(number - 2) + Fibonacci(number - 1);
}
 
Source : Robert Bell 
 

Paper Library For Storing Current User

Library Github link : Paper Library Link






This library use to remember current login user.

Tuesday, January 8, 2019

Make corner shape Edit text in android


create a xml file in drawable and code like that:


<?xmlversion="1.0"encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp"/>

<!--forpadding-->
<stroke
android:width="1.5dp"
android:color="#000"/>

<solid
android:color="#fff"/>

then in your edit text make the background this drawable xml file.

you can also use it in button, textView, imageView and many more widgets in android studio.

</shape>

Firebase New Dependency


For each project :

classpath 'com.google.gms:google-services:4.2.0' (in project level)

 apply plugin: 'com.google.gms.google-services' (in app level under dependency section)
implementation 'com.google.firebase:firebase-core:16.0.6'(in app level dependency section)


………………………………………..

implementation 'com.google.firebase:firebase-firestore:17.1.5'
com.google.firebase:firebase-core:16.0.6
Analytics
com.google.firebase:firebase-database:16.0.5
Realtime Database
com.google.firebase:firebase-firestore:17.1.5
Cloud Firestore
com.google.firebase:firebase-storage:16.0.5
Storage
com.crashlytics.sdk.android:crashlytics:2.9.7
Crashlytics
com.google.firebase:firebase-auth:16.1.0
Authentication
com.google.firebase:firebase-messaging:17.3.4
Cloud Messaging
com.google.firebase:firebase-config:16.1.2
Remote Config
com.google.firebase:firebase-invites:16.0.6
Invites and Dynamic Links
com.google.firebase:firebase-ads:17.1.2
AdMob
com.google.firebase:firebase-appindexing:17.1.0
App Indexing
com.google.firebase:firebase-perf:16.2.3
Performance Monitoring
com.google.firebase:firebase-functions:16.1.3
Cloud Functions for Firebase Client SDK
com.google.firebase:firebase-ml-vision:18.0.2
ML Kit (Vision)
com.google.firebase:firebase-ml-model-interpreter:16.2.4
ML Kit (Custom Model)



From <https://firebase.google.com/docs/android/setup#use_the_firebase_assistant>

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