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

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