battle programmers alliance
Would you like to react to this message? Create an account in a few clicks or log in to continue.

battle programmers allianceLog in

battle programming a forum for elite programmers with extreme will power to sharpen their skills

android mobile app development grimoire

3 posters

descriptionandroid mobile app development grimoire - Page 5 Emptyandroid studio close an app programmatically

more_horiz
finish();
System.exit(0);

:rlx:

Last edited by Moti Barski on Sat Feb 06, 2021 7:21 pm; edited 1 time in total

descriptionandroid mobile app development grimoire - Page 5 Emptycreate and use an android library walkthrough

more_horiz
android mobile app development grimoire - Page 5 34z26f



How to create your own Android Library and publish it

open a new project, file, new, new module, select : android library, name it : somethinglibrary
add desired classes to said module in the java folder.
uplaod the project folder to github (see git hub walkthrough
https://www.yotamarker.com/t176p25-ios-app-dev?highlight=github#514 )

on github in said repo : click releases, publish release.
open jitpack.io, Insert your repository address (repoAccountName)/libraryname, lookup,
get it.

from the results : copy paste : maven {url 'https://jitpack.io'} to the gradle.build of the project
in repositories which is in allprojects

and copy paste the dependency(the one with compile) in gradle.build of the app in dependencies{}

:farao:

Last edited by Moti Barski on Sat Feb 06, 2021 7:22 pm; edited 1 time in total

descriptionandroid mobile app development grimoire - Page 5 Emptyandroid studio toggle black screen time out

more_horiz
android mobile app development grimoire - Page 5 3rfugm

toggle screen timeout :

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
or
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
to disable the screen timeout and
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
to re-enable it.

or

Code:

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:keepScreenOn="true">


meaning : in the xml : android:keepScreenOn="true"

:morph:

descriptionandroid mobile app development grimoire - Page 5 EmptyRe: android mobile app development grimoire

more_horiz
android studio simple recycler view updated walkthrough

right click java classes folder at left explorer window and add a new empty activity.

activity_select_device.xml :

Code:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".SelectDeviceActivity">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/deviceList"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>


SelectDeviceActivity:

Code:

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.os.Bundle;

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

public class SelectDeviceActivity extends AppCompatActivity {

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

        // Instantiate RecyclerView
        RecyclerView recyclerView = findViewById(R.id.deviceList);

        List<Object> deviceList = new ArrayList<>();//list with displayed objects
        

        // Setting Up RecyclerView
        recyclerView.setLayoutManager(new LinearLayoutManager(this));

        ListAdapter listAdapter = new ListAdapter(this,deviceList);
        recyclerView.setAdapter(listAdapter);


    }
}


n the res, layout directory add a layout for the items in the recycler view :
item_layout.xml :

Code:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/textItem"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:textSize="18sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <View
        android:id="@+id/divider"
        android:layout_width="409dp"
        android:layout_height="1dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:background="?android:attr/listDivider"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textItem" />
</androidx.constraintlayout.widget.ConstraintLayout>


add 2 more java classes :

Code:

public class DeviceInfoModel {

    private String deviceName, deviceHardwareAddress;

    public DeviceInfoModel(){}

    public DeviceInfoModel(String deviceName, String deviceHardwareAddress){
        this.deviceName = deviceName;
        this.deviceHardwareAddress = deviceHardwareAddress;
    }

    public String getDeviceName(){return deviceName;}

    public String getDeviceHardwareAddress(){return deviceHardwareAddress;}

}


ListAdapter :

Code:

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class ListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context context;
    private List<Object> deviceList;

    public static class ViewHolder extends RecyclerView.ViewHolder {
        TextView textName;

        public ViewHolder(View view){
            super(view);
            textName = view.findViewById(R.id.textItem);
        }
    }

    public ListAdapter(Context context, List<Object> deviceList){
        this.context = context;
        this.deviceList = deviceList;
    }

    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_layout,parent,false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    public void onBindViewHolder(RecyclerView.ViewHolder holder,int position){
        // Get Device Name and Device Address
        DeviceInfoModel deviceInfoModel = (DeviceInfoModel) deviceList.get(position);
        String deviceName = deviceInfoModel.getDeviceName();
        final String deviceAddress = deviceInfoModel.getDeviceHardwareAddress();

        // Assign Device name to the list
        ViewHolder itemHolder = (ViewHolder) holder;
        itemHolder.textName.setText(deviceName);

        // Return to Main Screen when a device is selected
        // And pass device Address information to create connection
        itemHolder.textName.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, MainActivity.class);
                intent.putExtra("deviceAddress",deviceAddress);
                context.startActivity(intent);
            }
        });

    }

    public int getItemCount(){
        int dataCount = deviceList.size();
        return dataCount;
    }

}


code to summon the activity with the recycler view (put this code in your MainActivity) :

Intent intent = new Intent(MainActivity.this, SelectDeviceActivity.class);
startActivity(intent);

get selectet device chosen :
deviceAddress = getIntent().getStringExtra("deviceAddress");
if (deviceAddress != null){}//handle choiced result here

Last edited by Moti Barski on Sat Feb 06, 2021 7:23 pm; edited 1 time in total

descriptionandroid mobile app development grimoire - Page 5 EmptyRe: android mobile app development grimoire

more_horiz
add animation to recycler view:

recycler animation beef up :

res, create anim folder, add :
1 item_animation_fall_down.xml :

XML:

Code:

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

    android:duration="2000">



    <translate

        android:fromYDelta="-20%"

        android:toYDelta="0"

        android:interpolator="@android:anim/decelerate_interpolator"

        />



    <alpha

        android:fromAlpha="0"

        android:toAlpha="1"

        android:interpolator="@android:anim/decelerate_interpolator"

        />



    <scale

        android:fromXScale="105%"

        android:fromYScale="105%"

        android:toXScale="100%"

        android:toYScale="100%"

        android:pivotX="50%"

        android:pivotY="50%"

        android:interpolator="@android:anim/decelerate_interpolator"

        />



</set>


android:duration="2000" is how long the animation runs

and layout_animation_fall_down.xml :

XML:

Code:

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

<layoutAnimation

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

    android:animation="@anim/item_animation_fall_down"

    android:delay="15%"

    android:animationOrder="normal"

    />


bind the animation to the xml recycler widget like this view xml attribute :

android:layoutAnimation="@anim/layout_animation_fall_down"

descriptionandroid mobile app development grimoire - Page 5 EmptyRe: android mobile app development grimoire

more_horiz


https://www.yotamarker.com/t342-java-android-studio-control-droiduino-bluetooth-arduino-with-bluetooth

Last edited by Moti Barski on Tue Feb 16, 2021 5:10 am; edited 1 time in total

descriptionandroid mobile app development grimoire - Page 5 EmptyRe: android mobile app development grimoire

more_horiz
publish or sell app on amazon



https://developer.amazon.com/en/
developer consol, android app
app sku com.domain.app
availability and pricing tab :

add description tab

images & multimedia :
512x512 png
114x114 png
3 screenshots

promotional image : 1024 x 500 landscape png or jpg
video 720 4:3 or 16:9 or higher
privacy_tip Permissions in this forum:
You cannot reply to topics in this forum