~samwhited/oslp

769ed1ec2fb2fffdecc36ec35dfbd4634f264194 — Sam Whited 3 years ago 7e24a3f
Use native snackbar
M src/main/java/com/samwhited/opensharelocationplugin/activities/ShareLocationActivity.java => src/main/java/com/samwhited/opensharelocationplugin/activities/ShareLocationActivity.java +18 -16
@@ 8,13 8,13 @@ import android.location.LocationListener;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.samwhited.opensharelocationplugin.R;
import com.samwhited.opensharelocationplugin.overlays.Marker;


@@ 28,7 28,7 @@ import org.osmdroid.util.GeoPoint;
public class ShareLocationActivity extends LocationActivity implements LocationListener {

    private static final String KEY_FIXED_TO_LOC = "fixed_to_loc";
    private RelativeLayout snackBar;
    private Snackbar snackBar;
    private boolean marker_fixed_to_loc = false;
    private MenuItem toggle_fixed_location_item;
    private Boolean noAskAgain = false;


@@ 64,17 64,19 @@ public class ShareLocationActivity extends LocationActivity implements LocationL
        });

        // Setup the snackbar
        this.snackBar = findViewById(R.id.snackbar);
        final TextView snackbarAction = findViewById(R.id.snackbar_action);
        snackbarAction.setOnClickListener(view -> {
            if (isLocationEnabledAndAllowed()) {
                updateUi();
            } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !hasLocationPermissions()) {
                requestPermissions(REQUEST_CODE_SNACKBAR_PRESSED);
            } else if (!isLocationEnabled()) {
                startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
            }
        });
        final CoordinatorLayout snackBarCoordinator = findViewById(R.id.snackbarCoordinator);
        if (snackBarCoordinator != null) {
            this.snackBar = Snackbar.make(snackBarCoordinator, R.string.location_disabled, Snackbar.LENGTH_INDEFINITE);
            snackBar.setAction(R.string.enable, view -> {
                if (isLocationEnabledAndAllowed()) {
                    updateUi();
                } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !hasLocationPermissions()) {
                    requestPermissions(REQUEST_CODE_SNACKBAR_PRESSED);
                } else if (!isLocationEnabled()) {
                    startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                }
            });
        }

        // Setup the share button
        final Button shareButton = findViewById(R.id.share_button);


@@ 237,9 239,9 @@ public class ShareLocationActivity extends LocationActivity implements LocationL
    @Override
    protected void updateUi() {
        if (noAskAgain || isLocationEnabledAndAllowed()) {
            this.snackBar.setVisibility(View.GONE);
            this.snackBar.dismiss();
        } else {
            this.snackBar.setVisibility(View.VISIBLE);
            this.snackBar.show();
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            // Setup the fab button on v21+ devices

D src/main/res/drawable/snackbar.xml => src/main/res/drawable/snackbar.xml +0 -16
@@ 1,16 0,0 @@
<?xml version="1.0" encoding="UTF-8"?><!--
Resource copied from Conversations and the official Location sharing plugin by iNPUTmice.
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <solid android:color="@color/darkbackground" />

    <corners android:radius="8dip" />

    <padding
        android:bottom="0dip"
        android:left="0dip"
        android:right="0dip"
        android:top="0dip" />

</shape>
\ No newline at end of file

M src/main/res/layout-v21/activity_share_location.xml => src/main/res/layout-v21/activity_share_location.xml +58 -95
@@ 1,106 1,69 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.samwhited.opensharelocationplugin.activities.ShareLocationActivity"
    android:id="@+id/snackbarCoordinator"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.samwhited.opensharelocationplugin.activities.ShareLocationActivity">

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@id/button_bar">

        <org.osmdroid.views.MapView
            android:id="@+id/map"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/toggle_fixed_marker_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="end|bottom"
            android:layout_margin="16dp"
            android:background="@color/accent"
            android:contentDescription="@string/action_unfix_from_location"
            android:src="@drawable/ic_gps_fixed_white_24dp"
            android:tint="@android:color/white" />
    </FrameLayout>

    <!-- Parts of this resource are copied from the official location sharing plugin by iNPUTmice -->
    android:layout_height="match_parent">
    <RelativeLayout
        android:id="@+id/snackbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/button_bar"
        android:layout_marginBottom="4dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="4dp"
        android:background="@drawable/snackbar"
        android:minHeight="48dp"
        android:visibility="visible">
        android:layout_height="match_parent">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_centerVertical="true"
            android:layout_toStartOf="@+id/snackbar_action"
            android:paddingStart="24dp"
            android:text="@string/location_disabled"
            android:textColor="@color/ondarktext"
            android:textSize="?attr/TextSizeBody"
            tools:ignore="RtlSymmetry" />
        <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_above="@id/button_bar">

        <TextView
            android:id="@+id/snackbar_action"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentTop="true"
            android:paddingBottom="16dp"
            android:paddingLeft="24dp"
            android:paddingRight="24dp"
            android:paddingTop="16dp"
            android:text="@string/enable"
            android:textAllCaps="true"
            android:textColor="@color/ondarktext"
            android:textSize="?attr/TextSizeBody"
            android:textStyle="bold" />
    </RelativeLayout>
            <org.osmdroid.views.MapView
                android:id="@+id/map"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

    <LinearLayout
        android:id="@+id/button_bar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        tools:ignore="RtlHardcoded">
            <android.support.design.widget.FloatingActionButton
                android:id="@+id/toggle_fixed_marker_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="end|bottom"
                android:layout_margin="16dp"
                android:background="@color/accent"
                android:contentDescription="@string/action_unfix_from_location"
                android:src="@drawable/ic_gps_fixed_white_24dp"
                android:tint="@android:color/white" />
        </FrameLayout>

        <Button
            android:id="@+id/cancel_button"
            style="?android:attr/borderlessButtonStyle"
            android:layout_width="0dp"
        <LinearLayout
            android:id="@+id/button_bar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/cancel"
            android:textColor="@color/primarytext" />
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            tools:ignore="RtlHardcoded">

        <View
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:layout_marginBottom="7dp"
            android:layout_marginTop="7dp"
            android:background="@color/divider" />
            <Button
                android:id="@+id/cancel_button"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="@string/cancel"
                android:textColor="@color/primarytext" />

        <Button
            android:id="@+id/share_button"
            style="?android:attr/borderlessButtonStyle"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/share"
            android:textColor="@color/primarytext" />
    </LinearLayout>
</RelativeLayout>
            <View
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:layout_marginBottom="7dp"
                android:layout_marginTop="7dp"
                android:background="@color/divider" />

            <Button
                android:id="@+id/share_button"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="@string/share"
                android:textColor="@color/primarytext" />
        </LinearLayout>
    </RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
\ No newline at end of file

M src/main/res/layout/activity_share_location.xml => src/main/res/layout/activity_share_location.xml +45 -82
@@ 1,91 1,54 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.samwhited.opensharelocationplugin.activities.ShareLocationActivity"
    android:id="@+id/snackbarCoordinator"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.samwhited.opensharelocationplugin.activities.ShareLocationActivity">

    <org.osmdroid.views.MapView
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/button_bar" />

    <!-- Parts of this resource are copied from the official location sharing plugin by iNPUTmice -->
    android:layout_height="match_parent">
    <RelativeLayout
        android:id="@+id/snackbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/button_bar"
        android:layout_marginBottom="4dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="4dp"
        android:background="@drawable/snackbar"
        android:minHeight="48dp"
        android:visibility="visible">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_centerVertical="true"
            android:layout_toStartOf="@+id/snackbar_action"
            android:paddingStart="24dp"
            android:text="@string/location_disabled"
            android:textColor="@color/ondarktext"
            android:textSize="?attr/TextSizeBody"
            tools:ignore="RtlSymmetry" />
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/snackbar_action"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentTop="true"
            android:paddingBottom="16dp"
            android:paddingLeft="24dp"
            android:paddingRight="24dp"
            android:paddingTop="16dp"
            android:text="@string/enable"
            android:textAllCaps="true"
            android:textColor="@color/ondarktext"
            android:textSize="?attr/TextSizeBody"
            android:textStyle="bold" />
    </RelativeLayout>

    <LinearLayout
        android:id="@+id/button_bar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        tools:ignore="RtlHardcoded">

        <Button
            android:id="@+id/cancel_button"
            style="?android:attr/borderlessButtonStyle"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/cancel"
            android:textColor="@color/primarytext" />

        <View
            android:layout_width="1dp"
        <org.osmdroid.views.MapView
            android:id="@+id/map"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="7dp"
            android:layout_marginTop="7dp"
            android:background="@color/divider" />
            android:layout_above="@+id/button_bar" />

        <Button
            android:id="@+id/share_button"
            style="?android:attr/borderlessButtonStyle"
            android:layout_width="0dp"
        <LinearLayout
            android:id="@+id/button_bar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/share"
            android:textColor="@color/primarytext" />
    </LinearLayout>
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            tools:ignore="RtlHardcoded">

            <Button
                android:id="@+id/cancel_button"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="@string/cancel"
                android:textColor="@color/primarytext" />

            <View
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:layout_marginBottom="7dp"
                android:layout_marginTop="7dp"
                android:background="@color/divider" />

            <Button
                android:id="@+id/share_button"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="@string/share"
                android:textColor="@color/primarytext" />
        </LinearLayout>

</RelativeLayout>
    </RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
\ No newline at end of file