Element and Swipe Gester app

  // Element and Swipe Gester App 


// MainActivity.java *************************************

package com.mycompany.myapp2;


import android.app.ActionBar;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.GestureDetector;

import android.view.MotionEvent;

import android.view.View;

import android.widget.ArrayAdapter;

import android.widget.AutoCompleteTextView;

import android.widget.LinearLayout;

import android.widget.TextView;

import android.widget.Toast;

import android.view.Menu;

import android.view.MenuInflater;

import android.view.MenuItem;


public class MainActivity extends Activity {


    SwipeListener swipelistener;

    LinearLayout main;

TextView textView; 

    AutoCompleteTextView autoCompleteTextView;

    ArrayAdapter adapter;

    String value;

    public static final String key_Text = "com.mycompany.myapp2";

    String[] nameList = {

        "H","He","Li","Be","B","C","N","O","F","Ne",

        "Na","Mg","Al","Si","P","S","Cl","Ar","K","Ca",

        "Sc","Ti","V","Cr","Mn","Fe","Co","Ni","Cu","Zn",

        "Ga","Ge","As","Se","Br","Kr","Rb","Sr","Y","Zr"    };


    String sendArr[]={"H","He","Li","Be","B","C","N","O","F","Ne"};

        

        

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);


        

        // assign Values in varrible

        main = findViewById(R.id.relativ);

        autoCompleteTextView = findViewById(R.id.autoCompleteTextView);



        // for hiden ToolBar or ActoinBar

         ActionBar actionBar= getActionBar();

         actionBar.setSubtitle("\nHello guy in this platform we learn preodic table in details\nEnter element symbol and swipe left to open all details about element");               

       //  actionBar.setDisplayOptions(3);




        adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, nameList);

        autoCompleteTextView.setThreshold(1);//start searching from 1 character

        autoCompleteTextView.setAdapter(adapter);




        // called a swipeListener class

        swipelistener = new SwipeListener(main);


    }


    @Override

    public boolean onCreateOptionsMenu(Menu menu) {

        MenuInflater mi= getMenuInflater();

        mi.inflate(R.menu.menu,menu);

        

        return true;

    }


    @Override

    public boolean onOptionsItemSelected(MenuItem item) {

        switch(item.getItemId()){

            case R.id.share:

                Intent in = new Intent(Intent.ACTION_SEND);

                in.setType("text/plain");

                in.putExtra(Intent.EXTRA_TEXT,"*my web site*\nwww.com");

                startActivity(in);

        }

        return true;

    }

    

    


    

    

    

    

    

    

    



    // create a Class (in class)


    private class SwipeListener implements View.OnTouchListener {


        GestureDetector gesturedetector;

        public int i=0;


        // Create a constructor 

        SwipeListener(View view) {


            final int  threshold = 100;

            final  int velocity_threshold=100;


            GestureDetector.SimpleOnGestureListener listener =

                new GestureDetector.SimpleOnGestureListener(){

                public boolean onDown(MotionEvent e) {


                    return true;

                }


                public boolean  onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {


                    float xDiff = e2.getX() - e1.getX();

                    float yDiff = e2.getY() - e1.getY();


                    try {

                        if (Math.abs(xDiff) > Math.abs(yDiff)) {


                            if (Math.abs(xDiff) > threshold &&

                                Math.abs(velocityX) > velocity_threshold) {


                                if (xDiff > 0) {

                                    while (i < 4) {

                                        String []number={"One","Two","Three","Four","Five"};

                                        textView.setText(number[1] + " Swipe Right");

                                        i++;

                                    }




                                } else {


                                    Intent in= new Intent(MainActivity.this, activity2.class);

                                    value= autoCompleteTextView.getText().toString();

                                    in.putExtra(key_Text, value);

                                    in.putExtra("element",sendArr);

                                    startActivity(in);



                                }


                            }

                            return true;

                        } else {

                            if (Math.abs(xDiff) > threshold 

                                && Math.abs(velocityX) > velocity_threshold) {

                                if (yDiff > 0) {


                                    textView.setText("Down ");

                                } else {


                                    textView.setText("up");

                                }

                                return true;

                            }


                        }


                    } catch (Exception e) {

                        e.printStackTrace();

                    }

                    return false;

                }

            };

            gesturedetector = new GestureDetector(listener);

            view.setOnTouchListener(this);

        }

        @Override

        public boolean onTouch(View p1, MotionEvent p2) {


            return gesturedetector.onTouchEvent(p2);

        }


    }

}



// Activity2.java ****************************************


package com.mycompany.myapp2;


import android.app.ActionBar;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.widget.TextView;

import android.widget.Toast;

import java.util.ArrayList;


public class activity2 extends Activity {


    // Initialize Varriables

    TextView txt, num, weight;

    String ss;

    Intent in;


@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity2);


        // Assign Value in Varriable

        txt = findViewById(R.id.element);

        num = findViewById(R.id.number);

        weight = findViewById(R.id.wet);


        

        // hide Action bar 

        ActionBar ac = getActionBar();

        ac.hide();


        ArrayList<String> arr = new ArrayList<>();

        ArrayList<Integer> array=new ArrayList<>();


        int j=1;

        for (int i=0;i <= 40;i++) {

            array.add(i, j);

            j++;

        }

        


        arr.add("H"); 

        arr.add("He");

        arr.add("Li");

        arr.add("Be");

        arr.add("B");

        arr.add("C");

        arr.add("N");

        arr.add("O");

        arr.add("F");

        arr.add("Ne");

        arr.add("Na");

        arr.add("Mg");

        arr.add("Al");

        arr.add("Si");

        arr.add("P");

        arr.add("S");

        arr.add("Cl");

        arr.add("Ar");

        arr.add("K");

        arr.add("Ca");

        arr.add("Sc");

        arr.add("Ti");

        arr.add("V");

        arr.add("Cr");

        arr.add("Mn");

        arr.add("Fe");

        arr.add("Co");

        arr.add("Ni");

        arr.add("Cu");

        arr.add("Zn");

        arr.add("Ga");

        arr.add("Ge");

        arr.add("As");

        arr.add("Se");

        arr.add("Br");

        arr.add("Kr");

        arr.add("Rb");

        arr.add("Sr");

        arr.add("Y");

        arr.add("Zr");

        

        String[]ar={};


        in =getIntent();     // get value or string of first Activity

        ss = in.getExtras().getString(MainActivity.key_Text);

        try {

            txt.setText(arr.get(arr.indexOf(ss)));

            int fff= array.get(arr.indexOf(ss));

            num.setText(fff + "");

            weight.setText(fff + fff + "");

        } catch (Exception e) {

            Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();

        }

        

        

     Intent intent= getIntent();

        String ss[]= intent.getExtras().getStringArray("element");


//     StringBuilder build_text=new StringBuilder();

//     for(int oo=0;oo<ss.length;oo++){

//         build_text.append(ss[oo]+" ");

//     }

     

        Toast.makeText(this, ss[0]+"", Toast.LENGTH_LONG).show();

     

  }

}





// main.xml **********************************************


<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:id="@+id/relativ"

android:gravity="top|center"

android:layout_marginTop="27dp">


<AutoCompleteTextView

android:id="@+id/autoCompleteTextView"

android:layout_height="wrap_content"

android:layout_width="match_parent"

android:layout_margin="70dp"/>


</LinearLayout>



// activity2.xml ******************************************


<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="match_parent"

android:gravity="top|center"

android:orientation="vertical"

android:background="#C4FFA630">


<LinearLayout

android:orientation="horizontal"

android:layout_width="match_parent"

android:layout_height="100dp"

android:layout_margin="15dp"

android:background="#FFF0E3FF"

android:layout_marginTop="75dp">


<LinearLayout

android:orientation="vertical"

android:layout_width="30dp"

android:layout_height="match_parent"

android:gravity="center_horizontal"

android:layout_marginLeft="10dp">


<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="4"

android:layout_marginTop="10dp"

android:gravity="center"

android:textSize="18sp"

android:textColor="#FF004349"

android:textStyle="bold|italic"

android:id="@+id/wet"/>


<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="2"

android:layout_marginTop="37dp"

android:gravity="center"

android:textSize="18sp"

android:textColor="#FF004349"

android:textStyle="bold|italic"

android:id="@+id/number"/>


</LinearLayout>


<LinearLayout

android:orientation="vertical"

android:layout_width="50dp"

android:layout_height="match_parent"

android:gravity="center_vertical">


<TextView

android:layout_width="wrap_content"

android:layout_height="match_parent"

android:text="He"

android:gravity="center"

android:textSize="39sp"

android:textColor="#FF004349"

android:textStyle="italic"

android:id="@+id/element"/>


</LinearLayout>


<LinearLayout

android:orientation="vertical"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gravity="center">


<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Hellium"

android:textSize="24sp"

android:textColor="#FFFA3737"/>


<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="निष्क्रिय गैसें"

android:layout_marginTop="10dp"

android:textColor="#FF677AD3"/>


</LinearLayout>


</LinearLayout>


<LinearLayout

android:orientation="vertical"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="#D4FFFFFF"

android:layout_margin="15dp"/>


</LinearLayout>



// menu.xml ***********************************************

<menu xmlns:android="http://schemas.android.com/apk/res/android">

    

    <item

        android:id="@+id/setting"

        android:title="Setting"/>

    

    <item

        android:id="@+id/contain"

        android:title="Containt"/>

    <item

        android:id="@+id/item"

        android:title="Item"/>

    <item

        android:id="@+id/exit"

        android:title="Exit"/>

    

    

    <item

        android:title="Share"

        android:id="@+id/share"

        android:showAsAction="ifRoom|withText"

        android:icon="@android:drawable/ic_menu_share"

        />

    

    

</menu>