battle programmers alliance

battle programminga forum for elite programmerswith extreme will powerto sharpen theire skills
 
HomeCalendarFAQSearchMemberlistUsergroupsRegisterLog in
Search
 
 

Display results as :
 
Rechercher Advanced Search
Latest topics
» android mobile app dev APK
Sun Jul 15, 2018 6:20 pm by Moti Barski

» android studio execises
Mon Jul 09, 2018 1:43 pm by Moti Barski

» problem with firebase authentication
Thu Jun 28, 2018 9:52 am by Moti Barski

» text art canvas
Wed Jun 20, 2018 8:55 pm by Moti Barski

» links/suggestions to become a programmer
Mon May 07, 2018 11:01 pm by Moti Barski

» java eclipse oxygen grimoire
Thu May 03, 2018 8:24 pm by Moti Barski

» forum logo by tf monkey
Wed May 02, 2018 10:17 pm by Moti Barski

» java and MySQL
Mon Apr 30, 2018 3:02 pm by Admin

» mini A.I puzzles
Mon Apr 23, 2018 11:38 am by Moti Barski

July 2018
SunMonTueWedThuFriSat
1234567
891011121314
15161718192021
22232425262728
293031    
CalendarCalendar
Social bookmarking
Social bookmarking digg  Social bookmarking delicious  Social bookmarking reddit  Social bookmarking stumbleupon  Social bookmarking slashdot  Social bookmarking yahoo  Social bookmarking google  Social bookmarking blogmarks  Social bookmarking live      

Bookmark and share the address of battle programmers alliance on your social bookmarking website
Share | 
 

 android studio execises

Go down 
AuthorMessage
Moti Barski

avatar

Posts : 154
Join date : 2011-08-02

PostSubject: android studio execises   Mon Jul 09, 2018 1:43 pm

image based dialer for old people with custom list view:

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

build.gradle module add :

implementation 'com.github.bumptech.glide:glide:4.7.1'


add dimens.xml to res, values :
Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <dimen name="edge">16dp</dimen>

</resources>

main xml :

Code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_margin="@dimen/edge"
    >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="My List"
        android:gravity="center"
        android:textSize="22sp"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Add Data"
        android:background="#009fff"
        android:textColor="#fff"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:id="@+id/btnAdd"
        />
    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/myLst"/>
</LinearLayout>


partinias xml (for the custom list in the main xml):

Code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="200dp">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ImageView
            android:layout_width="250dp"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher_background"
            android:layout_gravity="center"

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

        <Button
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:background="#009fff"
            android:textColor="#fff"
            android:text="DIAL"
            android:layout_gravity="center"

            android:id="@+id/btnDial"/>
    </LinearLayout>
</FrameLayout>


MyContacts java :


Code:
package com.justforum.yotamarker.lisbaseadapter;

import android.widget.ImageView;

public class MyContacts {
    private String url;
    private String myName;
    private String dialer;

    public MyContacts(String myName, String dialer, String url) {
        this.myName = myName;
        this.dialer = dialer;
        this.url=url;
    }

    public String getMyName() {
        return myName;
    }

    public String getDialer() {
        return dialer;
    }

    public String getUrl()
    {
        return url;
    }
}


MyAdapter java :


Code:
package com.justforum.yotamarker.lisbaseadapter;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.support.v4.app.ActivityCompat;
import android.support.v4.view.LayoutInflaterCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;

import java.util.List;
import java.util.zip.Inflater;

public class MyAdapter extends BaseAdapter {
    List<MyContacts> myList;
    Context context;

    public MyAdapter(List<MyContacts> myList, Context context) {
        this.myList = myList;
        this.context = context;
    }

    @Override
    public int getCount() {
        return myList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        /*
        TextView myText = new TextView(context);
        myText.setText(myList.get(position));
        myText.setTextSize(50);
        return myText;
        */

        View view = LayoutInflater.from(context).inflate(R.layout.partinias,null,false);

        Button btnDial = view.findViewById(R.id.btnDial);
        btnDial.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(context, "you dial to:"+myList.get(position).getDialer(), Toast.LENGTH_SHORT).show();

                Intent callIntent = new Intent(Intent.ACTION_CALL);
                callIntent.setData(Uri.parse("tel:" + myList.get(position).getDialer()));
                if (ActivityCompat.checkSelfPermission(context,
                        Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                    return;
                }
                context.startActivity(callIntent);

            }
        });
        ImageView personImage = view.findViewById(R.id.imgPerson);
        Glide.with(context).load(myList.get(position).getUrl()).into(personImage);
        return view;

    }
}


main java :

Code:
package com.justforum.yotamarker.lisbaseadapter;

import android.Manifest;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    Context context;
    Button btnAdd;
    ListView lstData;
    private static final int REQUEST_PHONE_CALL = 1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // ensure enablement of phone calls
        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.CALL_PHONE)) {

            new AlertDialog.Builder(this)
                    .setTitle("Permission needed")
                    .setMessage("This permission is needed to make phone calls")
                    .setPositiveButton("ok", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            ActivityCompat.requestPermissions(MainActivity.this,
                                    new String[]{Manifest.permission.CALL_PHONE}, REQUEST_PHONE_CALL);
                        }
                    })
                    .setNegativeButton("cancel", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    })
                    .create().show();

        } else {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.CALL_PHONE}, REQUEST_PHONE_CALL);

        }

        setPointer();
    }

    private void setPointer() {
        this.context=this;
        btnAdd=findViewById(R.id.btnAdd);
        btnAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        lstData=findViewById(R.id.myLst);
        MyAdapter myAdapter=new MyAdapter(getData(),context);
        lstData.setAdapter(myAdapter);
    }

    public List<MyContacts> getData() {
        List<MyContacts> returnList = new ArrayList<>();
        returnList.add(new MyContacts("sarval chan","+972-666666666","http://pacific.network/wp-content/uploads/2017/02/hadoken.jpg"));
        return returnList;
    }
}

scratch

_________________
MB over and out
Back to top Go down
View user profile
 
android studio execises
Back to top 
Page 1 of 1
 Similar topics
-
» Trulia's Android Tablet Sweepstakes
» Golden Amazo Vs Super Android 17
» Dr. Dre Beats Giveaway *usa only*
» How to use ANT build to create HTML reports in Eclispe
» The Conduit heads to Android

Permissions in this forum:You cannot reply to topics in this forum
battle programmers alliance :: battle programming alliance :: chit chat-
Jump to: