Saturday, September 30, 2017

color code- common color code use in android studio

<resources>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>
    <color name="DeepOrange">#FF5722</color>
    <color name="Purple">#9C27B0</color>
    <item name="darkblue" type="color">#FF0099CC</item>
    <item name="darkpurple" type="color">#FF9933CC</item>
    <item name="darkgreen" type="color">#669900</item>
    <item name="darkorange" type="color">#FFFF8800</item>
    <item name="darkred" type="color">#FFCC0000</item>
    <color name="pink">#EB1460</color>
    <color name="deep_purple">#6633B9</color>
    <color name="indigo">#3D4DB7</color>
    <color name="light_blue">#00A6F6</color>
    <color name="cyan">#00BBD5</color>
    <color name="teal">#009687</color>
    <color name="light_green">#88C440</color>
    <color name="lime">#CCDD1E</color>
    <color name="yellow">#FFEC16</color>
    <color name="amber">#FFC100</color>
    <color name="deep_orange">#FF5505</color>
    <color name="brown">#7A5547</color>
    <color name="grey">#9D9D9D</color>
    <color name="blue_grey">#5E7C8B</color>
</resources>






Ad 1

how to share your app in share button- android studio

Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "https://play.google.com/store/apps/details?id=com.edupointbd.amirul.justAdmissionAid");
startActivity(Intent.createChooser(intent, "Share"));
return true;

Custom AlertDiolog using Inflater - layout xml- android studio

custom_title.xml


<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="#FF9800"    android:padding="16dp">

    <TextView        android:id="@+id/title"        android:text="are you sure"        android:textSize="20sp"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:textColor="#000" />

</RelativeLayout>




public void downloadSeat(View view) {

    AlertDialog.Builder builder = new AlertDialog.Builder(WrongSearch.this);
    View customTitleView = getLayoutInflater().inflate(R.layout.custom_title, null);
    TextView title = (TextView) customTitleView.findViewById(R.id.title);
    title.setText("Download Seat Plan");

   // builder.setTitle(Html.fromHtml("<font color='#FF7F27'>Download Seat Plan</font>"));    builder.setIcon(R.drawable.just);
    builder.setCustomTitle(customTitleView);
    builder.setMessage(Html.fromHtml("<font color='#2196F3'>Will You Download Seat Plan?</font>"));



    builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            downloadSeat();
        }
    });

    builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            Toast.makeText(getApplicationContext(),"Press YES for download",Toast.LENGTH_LONG).show();
        }
    });

    AlertDialog alert = builder.create();
    alert.show();



}


Alert Dialog - Three option in android Yes no cancel

public void downloadSeat(View view) {

    AlertDialog.Builder builder = new AlertDialog.Builder(WrongSearch.this);

    builder.setTitle(Html.fromHtml("<font color='#FF7F27'>Download Seat Plan</font>"));
    builder.setMessage("Are you Download Seat Plan? ");
    builder.setIcon(R.drawable.just);


    builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            downloadSeat();
        }
    });

    builder.setNegativeButton("View", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            Toast.makeText(getApplicationContext(),"No click",Toast.LENGTH_LONG).show();
        }
    });

    builder.setNeutralButton("CANCEL", new DialogInterface.OnClickListener()     {
        public void onClick(DialogInterface dialog, int id) {

        }
    });
    AlertDialog alert = builder.create();
    alert.show();

    

}

how to download image from server in android studio. using Download manager

need permission

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



import android.annotation.SuppressLint;
import android.app.DownloadManager;
import android.content.Context;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    Button down;
    DownloadManager downloadManager;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        down = (Button)findViewById(R.id.downloadFile);
        down.setOnClickListener(new View.OnClickListener() {
             
            @Override            public void onClick(View v) {
                downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
                Uri uri = Uri.parse("http://mandsit.com/amirul/assets/just/just_result.pdf");
               DownloadManager.Request request = new DownloadManager.Request(uri);
                request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                Long reference = downloadManager.enqueue(request);


            }
        });
    }
}









<?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.edupointbd.amirul.myapplication.MainActivity">


    <Button        android:text="donload file"        android:id="@+id/downloadFile"        android:layout_width="match_parent"        android:layout_height="wrap_content" />

</RelativeLayout>

Friday, September 29, 2017

check internet is available or not - android studio

public class InternetConnectionCheck {



    public static boolean isInternetAvailable(Context context) {
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
        if (activeNetwork == null) return false;

        switch (activeNetwork.getType()) {
            case ConnectivityManager.TYPE_WIFI:
                if ((activeNetwork.getState() == NetworkInfo.State.CONNECTED ||
                        activeNetwork.getState() == NetworkInfo.State.CONNECTING) &&
                        isInternet())
                    return true;
                break;
            case ConnectivityManager.TYPE_MOBILE:
                if ((activeNetwork.getState() == NetworkInfo.State.CONNECTED ||
                        activeNetwork.getState() == NetworkInfo.State.CONNECTING) &&
                        isInternet())
                    return true;
                break;
            default:
                return false;
        }
        return false;
    }

    private static boolean isInternet() {

        Runtime runtime = Runtime.getRuntime();
        try {
            Process ipProcess = runtime.exec("/system/bin/ping -c 1 8.8.8.8");
            int exitValue = ipProcess.waitFor();

            return (exitValue == 0);
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }

        return false;
    }





}

remove the previous activity while going to another activity - android studio



public void AgainSearch(View view){
    Intent i = new Intent(ShowResult.this,ResultJUST.class);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    this.finish();
    startActivity(i);

}

Display Alert Dialog when Back button press- android studio




@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {

    if ((keyCode == KeyEvent.KEYCODE_BACK)) {
        AlertDialog.Builder alertbox = new AlertDialog.Builder(MainActivity.this);
        alertbox.setIcon(R.drawable.just);
        alertbox.setTitle("You Want To Exit");
        alertbox.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface arg0, int arg1) {
                // finish used for destroyed activity                finish();
            }
        });

        alertbox.setNegativeButton("No", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface arg0, int arg1) {
                // Nothing will be happened when clicked on no button                // of Dialog            }
        });

        alertbox.show();
    }

    return super.onKeyDown(keyCode, event);
}

Wednesday, September 27, 2017

loginRegistration retrofit and MySql Slim Framwork

 

import com.google.gson.annotations.Expose;

/** * Created by Amirul on 26-Sep-17. */
public class LoginModel  {

    @Expose    private String status;
    @Expose    private String login;

    /**     * @return The status     */    public String getStatus() {
        return status;
    }

    /**     * @param status The status     */    public void setStatus(String status) {
        this.status = status;
    }

    /**     * @return The login     */    public String getLogin() {
        return login;
    }

    /**     * @param login The login     */    public void setLogin(String login) {
        this.login = login;
    }
}



package com.edupointbd.amirul.registerlogin.rest_Interface;

import com.edupointbd.amirul.registerlogin.model.LoginModel;

import retrofit.Callback;
import retrofit.http.Field;
import retrofit.http.FormUrlEncoded;
import retrofit.http.POST;

/** * Created by Amirul on 26-Sep-17. */
public interface RestInterface {
    //chnage your IP here if you working on local    // String url = "http://192.168.43.175/register-login/v1";    //For Hosting give the complete path before index.php    String url = "http://your domain name/register-login/v1";

    @FormUrlEncoded    @POST("/login")
    void Login(@Field("email") String email,
               @Field("pass") String pass, Callback<LoginModel> cb);

    @FormUrlEncoded    @POST("/signup")
    void SignUp(@Field("name") String name, @Field("email") String email,
                @Field("pass") String pass, Callback<LoginModel> pm);

}



---------------------------------------
 

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.Toast;

import com.edupointbd.amirul.registerlogin.model.LoginModel;
import com.edupointbd.amirul.registerlogin.rest_Interface.RestInterface;

import retrofit.Callback;
import retrofit.RestAdapter;
import retrofit.RetrofitError;
import retrofit.client.Response;

public class LoginActivity extends ActionBarActivity {

    EditText email,pass;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        email=(EditText)findViewById(R.id.input_email);
        pass=(EditText)findViewById(R.id.input_password);


        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#ffffff")));
        getSupportActionBar().setTitle(Html.fromHtml("<font color='#e12929'>Sign In</font>"));


    }




    // When Button Login clicked    public void Signin(View v){

        //Calling method of field validation        if(CheckFieldValidation()) {

            //progressBar.setVisibility(View.VISIBLE);            setContentView(R.layout.progressbar_layout);
            //making object of RestAdapter            RestAdapter adapter = new RestAdapter.Builder().setEndpoint(RestInterface.url).build();

            //Creating Rest Services            final RestInterface restInterface = adapter.create(RestInterface.class);

            //Calling method to get check login            restInterface.Login(email.getText().toString(), pass.getText().toString(), new Callback<LoginModel>() {
                @Override                public void success(LoginModel model, Response response) {

                    finish();
                    startActivity(getIntent());

                    email.setText("");
                    pass.setText("");


                    if (model.getStatus().equals("1")) {  //login Success
                        Toast.makeText(LoginActivity.this, "Login In SuccessFully", Toast.LENGTH_SHORT).show();
                        Intent i = new Intent(LoginActivity.this,AfterLoginActivity.class);
                        startActivity(i);

                    } else if (model.getStatus().equals("0"))  // login failure                    {
                        Toast.makeText(LoginActivity.this, "Invalid UserName/Pass ", Toast.LENGTH_SHORT).show();
                    }


                }

                @Override                public void failure(RetrofitError error) {
                    finish();
                    startActivity(getIntent());
                    String merror = error.getMessage();
                    Toast.makeText(LoginActivity.this, merror, Toast.LENGTH_LONG).show();
                }
            });
        }
    }

    //When Button Sign up clicked    public void SignUp(View v){

        Intent i= new Intent(LoginActivity.this,SignupActivity.class);
        startActivity(i);


    }

    //checking field are empty    private boolean CheckFieldValidation(){

        boolean valid=true;
        if(email.getText().toString().equals("")){
            email.setError("Can't be Empty");
            valid=false;
        }else if(pass.getText().toString().equals("")){
            pass.setError("Can't be Empty");
            valid=false;
        }

        return valid;

    }

}




xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:background="#E43F3F"    android:fitsSystemWindows="true"    android:fillViewport="false">

    <LinearLayout        android:orientation="vertical"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:paddingTop="56dp"        android:paddingLeft="24dp"        android:paddingRight="24dp">

        <ImageView android:src="@mipmap/ic_launcher"            android:layout_width="wrap_content"            android:layout_height="100dp"            android:layout_marginBottom="24dp"            android:layout_gravity="center_horizontal" />

        <!-- Email Label -->        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_marginTop="8dp"            android:layout_marginBottom="8dp">
            <EditText android:id="@+id/input_email"                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:inputType="textEmailAddress"                android:singleLine="true"                android:textColor="#ffffff"                android:textColorHint="#ffffff"                android:hint="Email" />
        </LinearLayout>

        <!-- Password Label -->        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_marginTop="8dp"            android:layout_marginBottom="8dp">
            <EditText android:id="@+id/input_password"                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:inputType="textPassword"                android:singleLine="true"                android:textColor="#ffffff"                android:textColorHint="#ffffff"                android:hint="Password"/>
        </LinearLayout>



        <android.support.v7.widget.AppCompatButton            android:id="@+id/btn_login"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:background="#C62828"            android:textColor="#ffffff"            android:textStyle="bold"            android:onClick="Signin"            android:layout_marginTop="24dp"            android:layout_marginBottom="24dp"            android:padding="12dp"            android:text="Login"/>

        <android.support.v7.widget.AppCompatButton            android:id="@+id/btn_signup"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:textColor="#C62828"            android:background="#ffffff"            android:textStyle="bold"            android:onClick="SignUp"            android:layout_marginBottom="24dp"            android:padding="12dp"            android:text="Not a member? Click here"/>

    </LinearLayout>
</ScrollView>


===========================================================

package com.edupointbd.amirul.registerlogin;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.Toast;

import com.edupointbd.amirul.registerlogin.model.LoginModel;
import com.edupointbd.amirul.registerlogin.rest_Interface.RestInterface;

import retrofit.Callback;
import retrofit.RestAdapter;
import retrofit.RetrofitError;
import retrofit.client.Response;

public class SignupActivity extends AppCompatActivity {

    EditText email,pass,name;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_signup);

        email=(EditText)findViewById(R.id.input_email);
        pass=(EditText)findViewById(R.id.input_password);
        name=(EditText)findViewById(R.id.input_name);


        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#ffffff")));
        getSupportActionBar().setTitle(Html.fromHtml("<font color='#e12929'>Sign Up</font>"));
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);


    }


    public void Signup(View v){


        //calling field validation method        if(CheckFieldValidation()) {

            setContentView(R.layout.progressbar_layout);
            //making object of RestAdapter            RestAdapter adapter = new RestAdapter.Builder().setEndpoint(RestInterface.url).build();

            //Creating Rest Services            final RestInterface restInterface = adapter.create(RestInterface.class);

            //Calling method to signup            restInterface.SignUp(name.getText().toString(), email.getText().toString(),
                    pass.getText().toString(), new Callback<LoginModel>() {
                        @Override                        public void success(LoginModel model, Response response) {

                            finish();
                            startActivity(getIntent());

                            email.setText("");
                            pass.setText("");
                            name.setText("");


                            if (model.getStatus().equals("1")) {  //Signup Success
                                Toast.makeText(SignupActivity.this, "Registered Successfully", Toast.LENGTH_SHORT).show();
                                finish();
                                Intent i = new Intent(SignupActivity.this, LoginActivity.class);
                                startActivity(i);

                            } else if (model.getStatus().equals("0"))  // Signup failure                            {
                                Toast.makeText(SignupActivity.this, "Email Already Registered", Toast.LENGTH_SHORT).show();
                            }


                        }

                        @Override                        public void failure(RetrofitError error) {
                            finish();
                            startActivity(getIntent());
                            String merror = error.getMessage();
                            Toast.makeText(SignupActivity.this, merror, Toast.LENGTH_LONG).show();
                        }
                    });
        }

    }

    //checking field are empty    private boolean CheckFieldValidation(){

        boolean valid=true;
        if(name.getText().toString().equals("")){
            name.setError("Can't be Empty");
            valid=false;
        }else if(email.getText().toString().equals("")){
            email.setError("Can't be Empty");
            valid=false;
        }else if(pass.getText().toString().equals("")){
            pass.setError("Can't be Empty");
            valid=false;
        }

        return valid;

    }


    @Override    public boolean onOptionsItemSelected(MenuItem menuItem) {
        if (menuItem.getItemId() == android.R.id.home) {
            finish();
        }
        return super.onOptionsItemSelected(menuItem);
    }



}

xml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:background="#E43F3F"    android:fitsSystemWindows="true">

    <LinearLayout        android:orientation="vertical"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:paddingTop="56dp"        android:paddingLeft="24dp"        android:paddingRight="24dp">

        <ImageView android:src="@drawable/ic_assignment_black_24px"            android:layout_width="100dp"            android:layout_height="100dp"            android:layout_marginBottom="24dp"            android:layout_gravity="center_horizontal" />


        <!-- Name Label -->        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_marginTop="8dp"            android:layout_marginBottom="8dp">
            <EditText android:id="@+id/input_name"                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:inputType="text"                android:singleLine="true"                android:textColor="#ffffff"                android:textColorHint="#ffffff"                android:hint="Name" />
        </LinearLayout>

        <!-- Email Label -->        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_marginTop="8dp"            android:layout_marginBottom="8dp">
            <EditText android:id="@+id/input_email"                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:inputType="textEmailAddress"                android:singleLine="true"                android:textColor="#ffffff"                android:textColorHint="#ffffff"                android:hint="Email" />
        </LinearLayout>

        <!-- Password Label -->        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_marginTop="8dp"            android:layout_marginBottom="8dp">
            <EditText android:id="@+id/input_password"                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:inputType="textPassword"                android:singleLine="true"                android:textColor="#ffffff"                android:textColorHint="#ffffff"                android:hint="Password"/>
        </LinearLayout>



        <android.support.v7.widget.AppCompatButton            android:id="@+id/btn_signup"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:background="#C62828"            android:textColor="#ffffff"            android:textStyle="bold"            android:onClick="Signup"            android:layout_marginTop="24dp"            android:layout_marginBottom="24dp"            android:padding="12dp"            android:text="Signup"/>

    </LinearLayout>
</ScrollView>

=========================================================

package com.edupointbd.amirul.registerlogin;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;

public class AfterLoginActivity extends ActionBarActivity {


    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_after_login);
        getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#ffffff")));
        getSupportActionBar().setTitle(Html.fromHtml("<font color='#e12929'>Home</font>"));


    }

}


<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:gravity="center"    android:background="#E43F3F"    android:layout_height="match_parent">

    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Welcome"        android:textSize="50sp"        android:textColor="#ffffff"        android:id="@+id/textView"        android:layout_gravity="center" />
</LinearLayout>



<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.edupointbd.amirul.registerlogin">

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

    <application        android:allowBackup="true"        android:icon="@mipmap/ic_launcher"        android:label="@string/app_name"        android:supportsRtl="true"        android:theme="@style/AppTheme">
        <activity android:name=".LoginActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".MainActivity" />
        <activity android:name=".SignupActivity" />
        <activity android:name=".AfterLoginActivity"></activity>
    </application>

</manifest>




dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'    })
    compile 'com.android.support:appcompat-v7:25.3.1'    compile 'com.squareup.retrofit:retrofit:1.9.0'    compile 'com.squareup.okhttp:okhttp:2.4.0'    testCompile 'junit:junit:4.12'}