Wednesday 23 May 2018

Android Runtime Permission with MyPermission Library in Kotlin

Android run time permission with MyPermission Library in Kotlin .
You can get Code from github DOWNLOAD

I am writing below Main Activity Code to have Access Permisssion

MainActivity.java
import android.Manifest
import android.os.Bundle
import com.stacklearning.mypermissionlibrary.MyPermission
import com.stacklearning.mypermissionlibrary.onPermisssionResult
class MainActivity : MyPermission() , onPermisssionResult {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        var permissionList = ArrayList<String>()
        permissionList.add( Manifest.permission.CAMERA)
        permissionList.add( Manifest.permission.WRITE_EXTERNAL_STORAGE)
        setPermission(this,permissionList,this)
    }
    override fun onPermissionGranted() {
        // open camera() and ...
        // ... etc what you want to do as per permission
    }
}


Here, We extend MainActivity from MyPermission() and Implement onPermissionResult
and we have to override onPermissionGranted() method .   to proceed with our code .

we have to pass PermissionList, like if we need camea permission, External Storage Permission and any other . Just pass this list to function   setPermission(this,permissionList,this) .


 If any problem in implementation, Please comment .












Wednesday 7 March 2018

Android Scanner App Tutorial With Zxing Library

Android Scanner Tutorial with Zxing Library


Today i am going to let you know how to make "Scanner App". I got lot of messages and comment to a make a tutorial on scanner . 

I have used Zxing Library, there are other libraries also. But i am using

Tuesday 6 March 2018

Custom ListView with Image and Text

Custom ListView with Android

Custom Listview is diffrent from SImple Listview in terms of complexity.
Like  simple Listview, custom ListView also uses Adapter to insert data from data source like as string array, array, database etc.   

Now in this tutorail you will learn  about how to customize list view with an image and text with title and its subtitle. 

So lets start from creating a project first,Open Android Studio, 
select FileNew > New Project. Put name your project CustomListView.

Application Name : CustomListView

Project Name : CustomListView
Package Name : com.stacklearning.Customlistview











Open layout file :

<?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:id="@+id/activity_main"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    tools:context="com.stacklearning.customlistview.MainActivity">

    <ListView        android:id="@+id/list"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_marginBottom="50dp">
    </ListView>
</RelativeLayout>
 
Open your MainActivity.java and paste the following code.
 
package com.stacklearning.customlistview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    ListView list;

    String[] maintitle ={
            "JellyBean","KitKat",
            "Lollipop","Marshmallow",
            "Nougat",
    };

    String[] subtitle ={
            "Sub Title 1","Sub Title 2",
            "Sub Title 3","Sub Title 4",
            "Sub Title 5",
    };

    Integer[] imgid={
            R.drawable.jellybean,R.drawable.kitkat,
            R.drawable.lollipop,R.drawable.marshmallow,
            R.drawable.nougat,
    };
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        MyListAdapter adapter=new MyListAdapter(this, maintitle, subtitle,imgid);
        list=(ListView)findViewById(R.id.list);
        list.setAdapter(adapter);

        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                // TODO Auto-generated method stub                if(position == 0) {
                    //code specific to first list item                    Toast.makeText(getApplicationContext(),"JellyBean",Toast.LENGTH_SHORT).show();
                }

                else if(position == 1) {
                    //code specific to 2nd list item                    Toast.makeText(getApplicationContext(),"KitKat",Toast.LENGTH_SHORT).show();
                }

                else if(position == 2) {

                    Toast.makeText(getApplicationContext(),"Lollipop",Toast.LENGTH_SHORT).show();
                }
                else if(position == 3) {

                    Toast.makeText(getApplicationContext(),"Marshmallow",Toast.LENGTH_SHORT).show();
                }
                else if(position == 4) {

                    Toast.makeText(getApplicationContext(),"Nougat",Toast.LENGTH_SHORT).show();
                }

            }
        });
    }
}
 
 Create an additional mylist.xml file in layout folder which contains view components displayed in listview.
 
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="horizontal"    android:layout_width="match_parent"    android:layout_height="match_parent">

    <ImageView        android:id="@+id/icon"        android:layout_width="60dp"        android:layout_height="60dp"        android:padding="5dp" />

    <LinearLayout android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:orientation="vertical">

        <TextView            android:id="@+id/title"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="Medium Text"            android:textStyle="bold"            android:textAppearance="?android:attr/textAppearanceMedium"            android:layout_marginLeft="10dp"            android:layout_marginTop="5dp"            android:padding="2dp"            android:textColor="#4d4d4d" />
        <TextView            android:id="@+id/subtitle"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="TextView"            android:layout_marginLeft="10dp"/>
    </LinearLayout>
</LinearLayout> 
 
Create another java class MyListAdapter.java which extends ArrayAdapter class. This class customizes our listview.  
 
package com.stacklearning.customlistview;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/** * Created by vspl on 6/3/18. */
public class MyListAdapter extends ArrayAdapter<String> {

    private final Activity context;
    private final String[] maintitle;
    private final String[] subtitle;
    private final Integer[] imgid;

    public MyListAdapter(Activity context, String[] maintitle,String[] subtitle, Integer[] imgid) {
        super(context, R.layout.mylist, maintitle);
        // TODO Auto-generated constructor stub
        this.context=context;
        this.maintitle=maintitle;
        this.subtitle=subtitle;
        this.imgid=imgid;

    }

    public View getView(int position, View view, ViewGroup parent) {
        LayoutInflater inflater=context.getLayoutInflater();
        View rowView=inflater.inflate(R.layout.mylist, null,true);

        TextView titleText = (TextView) rowView.findViewById(R.id.title);
        ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
        TextView subtitleText = (TextView) rowView.findViewById(R.id.subtitle);

        titleText.setText(maintitle[position]);
        imageView.setImageResource(imgid[position]);
        subtitleText.setText(subtitle[position]);

        return rowView;

    };
}



OutPut:




                            DOWNLOAD CODE

Monday 5 March 2018

Constraint Layout Android

Constraint Layout in Andorid :

Q: Why Constraint Layout in Android ? What is the need to use Constraint Layout?


There are some Problems in Standard Layout in Android .

Positioning Problems :Views are position using <Layout >elements like Relative layout, Linear layout or child elements itself . Lets take an example, if i need margin from

Friday 23 February 2018

Go to My App App Permission screen Setting




Navigate to App Setting in Android :


android app setting screen
Android App Setting Screen



Below is the code to navigate App Setting in Android . Sometimes we need to send user to App Setting Screen . Lets take an example, in Android Mashmallow device , if user permanent denied the permission then user has to

Android MVP Tutorial From Beginer to Advance Part 3

Android MVP Part 3


android-mvp-stack-learning
Android MVP Part 3



In this Article we are going to make a project with functionality Login  and HomePage via MVP Pattern.

                                                 DOWNLOAD CODE

If you are not clear with Basic of MVP Pattern, Please read first part of MVP and Second Part of MVP which shows the basic structure of MVP Pattern

Lets start . Continue with our project which have started in

Android MVP Tutorial From Beginer to Advance Part 2

                                                        Android MVP Part 2

android mvp -tutorial
Android MVP Tutorial
In this Article we are going to make a project with MVP .



If you are not clear with Basic of MVP Pattern, Please read first part of MVP.

Lets start . Make a new Project .

Add a Login

Android MVP Tutorial From Beginer to Advance Part 1


android-mvp-tutorial
Android MVP Tutorial
This Tutorial is based on Android Mvp, and we are going to teach you MVP part by part basis . This is the first part and you can go to second part here to learn more .


Android MVP

Mvp is Model View Presenter . MVP is a pattern to make the Android code stay clean . In Android MVC Pattern , Code is very messy, but in MVP Pattern View is

Thursday 22 February 2018

How to Create Server in Node js

const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});
Simple As it is .

We have to give Host Name and port number , and rest is the server code , that is

http.createServer(req, res)
server.listen(port, hostname) .

Android Runtime Permissions with Dexter Library (Simple Approach)

App Permission with Dexter Library

Android Runtime Permission With Dexter Library


Implementing Android runtime permissions intoduces in Mashmallow is a hard process and developer needs to write lot of code just to get a single permission.
User has to allow or deny any permission at runtime.

We are going to Use Dexter library to   simplify the process of adding the runtime permissions . 


With Dexter Library , we can have get "Single" runtime permission as well as "Multiple" runtime permission with just a

Wednesday 21 February 2018

Tuesday 20 February 2018

Monday 19 February 2018

Configure Build Variants in Android Gradle

 Want to make Multiple Flavour of an Andoid App ?

       Yes the solution is configure your build variant with diffrent flavours .




Build variant represents a different version of your app , Like one is debug app and one is release app
Like you want to create paid app  with no advertisement and free app with

Saturday 17 February 2018

Keeping the Device Awake Android ( Keep Screen On )

2 Ways  , We can Keep the screen On .


1 . XML
2. Coding


Via Xml  :

In the root of your layout xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:keepScreenOn="true">
    ...</LinearLayout>
Coding :

public class MyActivity extends Activity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
  }

Happy Coding . I appreciate your feedback .