Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2c8485c8 authored by Michael Chan's avatar Michael Chan
Browse files

Added support for launching custom apps for events

Bug: 6325441
Change-Id: Ieb8c7653321ccd28dfdcf0d02f4ce6be988501f2
parent 84fbd42c
Loading
Loading
Loading
Loading
+32 −3
Original line number Original line Diff line number Diff line
@@ -42,7 +42,6 @@
        android:id="@+id/event_info_scroll_view"
        android:id="@+id/event_info_scroll_view"
        android:orientation="vertical"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:fadingEdge="none"
        android:fadingEdge="none"
        android:animateLayoutChanges="true"
        android:animateLayoutChanges="true"
        android:layout_height="match_parent">
        android:layout_height="match_parent">
@@ -50,7 +49,6 @@
        <LinearLayout
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical">
            android:orientation="vertical">


            <!--  Container for the event's headline
            <!--  Container for the event's headline
@@ -269,7 +267,7 @@
                    android:text="@string/email_guests_label"
                    android:text="@string/email_guests_label"
                    android:layout_height="50dp"
                    android:layout_height="50dp"
                    android:layout_width="match_parent"
                    android:layout_width="match_parent"
                    android:layout_marginLeft="8dp"
                    android:layout_marginLeft="6dp"
                    android:layout_marginRight="8dp"
                    android:layout_marginRight="8dp"
                    android:gravity="center_vertical"
                    android:gravity="center_vertical"
                    android:paddingBottom="0dp"
                    android:paddingBottom="0dp"
@@ -284,6 +282,37 @@
                    style="@style/TextAppearance.EditEvent_LabelSmall" />
                    style="@style/TextAppearance.EditEvent_LabelSmall" />
            </LinearLayout>
            </LinearLayout>


            <!-- LAUNCH CUSTOM APP -->
            <LinearLayout
                android:id="@+id/launch_custom_app_container"
                android:visibility="gone"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <View
                    android:background="?android:attr/listDivider"
                    android:layout_height="1px"
                    android:layout_width="match_parent"
                    android:layout_marginLeft="8dip"
                    android:layout_marginRight="8dip" />
                <Button
                    android:id="@+id/launch_custom_app_button"
                    android:layout_height="50dp"
                    android:layout_width="match_parent"
                    android:layout_marginLeft="6dp"
                    android:layout_marginRight="8dp"
                    android:gravity="center_vertical"
                    android:paddingBottom="0dp"
                    android:layout_marginTop="0dip"
                    android:layout_marginBottom="0dip"
                    android:textAllCaps="false"
                    android:textSize="16sp"
                    android:textColor="#777777"
                    android:background="?android:attr/selectableItemBackground"
                    android:drawablePadding="8dp"
                    style="@style/TextAppearance.EditEvent_LabelSmall" />
            </LinearLayout>

            <!-- GUEST LIST -->
            <!-- GUEST LIST -->
            <com.android.calendar.event.AttendeesView
            <com.android.calendar.event.AttendeesView
                android:id="@+id/long_attendee_list"
                android:id="@+id/long_attendee_list"
+33 −1
Original line number Original line Diff line number Diff line
@@ -271,7 +271,7 @@
                    android:text="@string/email_guests_label"
                    android:text="@string/email_guests_label"
                    android:layout_height="50dp"
                    android:layout_height="50dp"
                    android:layout_width="match_parent"
                    android:layout_width="match_parent"
                    android:layout_marginLeft="8dp"
                    android:layout_marginLeft="5dp"
                    android:layout_marginRight="0dp"
                    android:layout_marginRight="0dp"
                    android:layout_gravity="left"
                    android:layout_gravity="left"
                    android:gravity="center_vertical"
                    android:gravity="center_vertical"
@@ -287,6 +287,38 @@
                    style="@style/TextAppearance.EditEvent_LabelSmall" />
                    style="@style/TextAppearance.EditEvent_LabelSmall" />
            </LinearLayout>
            </LinearLayout>


            <!-- LAUNCH CUSTOM APP -->
            <LinearLayout
                android:id="@+id/launch_custom_app_container"
                android:visibility="gone"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <View
                    android:background="?android:attr/listDivider"
                    android:layout_height="1px"
                    android:layout_width="match_parent"
                    android:layout_marginLeft="8dip"
                    android:layout_marginRight="0dip" />
                <Button
                    android:id="@+id/launch_custom_app_button"
                    android:layout_height="50dp"
                    android:layout_width="match_parent"
                    android:layout_marginLeft="5dp"
                    android:layout_marginRight="0dp"
                    android:layout_gravity="left"
                    android:gravity="center_vertical"
                    android:paddingBottom="0dp"
                    android:layout_marginTop="0dip"
                    android:layout_marginBottom="0dip"
                    android:textAllCaps="false"
                    android:textSize="16sp"
                    android:textColor="#777777"
                    android:background="?android:attr/selectableItemBackground"
                    android:drawablePadding="8dp"
                    style="@style/TextAppearance.EditEvent_LabelSmall" />
            </LinearLayout>

            <!-- GUEST LIST -->
            <!-- GUEST LIST -->
            <com.android.calendar.event.AttendeesView
            <com.android.calendar.event.AttendeesView
                android:id="@+id/long_attendee_list"
                android:id="@+id/long_attendee_list"
+106 −23
Original line number Original line Diff line number Diff line
@@ -16,15 +16,10 @@


package com.android.calendar;
package com.android.calendar;


import com.android.calendar.CalendarController.EventInfo;
import static android.provider.CalendarContract.EXTRA_EVENT_ALL_DAY;
import com.android.calendar.CalendarController.EventType;
import static android.provider.CalendarContract.EXTRA_EVENT_BEGIN_TIME;
import com.android.calendar.CalendarEventModel.Attendee;
import static android.provider.CalendarContract.EXTRA_EVENT_END_TIME;
import com.android.calendar.CalendarEventModel.ReminderEntry;
import static com.android.calendar.CalendarController.EVENT_EDIT_ON_LAUNCH;
import com.android.calendar.event.AttendeesView;
import com.android.calendar.event.EditEventActivity;
import com.android.calendar.event.EditEventHelper;
import com.android.calendar.event.EventViewUtils;
import com.android.calendarcommon.EventRecurrence;


import android.animation.Animator;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorListenerAdapter;
@@ -42,10 +37,14 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.content.res.Resources;
import android.database.Cursor;
import android.database.Cursor;
import android.graphics.Rect;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.net.Uri;
import android.os.Bundle;
import android.os.Bundle;
import android.provider.CalendarContract;
import android.provider.CalendarContract;
@@ -96,18 +95,22 @@ import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.Toast;


import com.android.calendar.CalendarController.EventInfo;
import com.android.calendar.CalendarController.EventType;
import com.android.calendar.CalendarEventModel.Attendee;
import com.android.calendar.CalendarEventModel.ReminderEntry;
import com.android.calendar.event.AttendeesView;
import com.android.calendar.event.EditEventActivity;
import com.android.calendar.event.EditEventHelper;
import com.android.calendar.event.EventViewUtils;
import com.android.calendarcommon.EventRecurrence;

import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Arrays;
import java.util.Collections;
import java.util.Collections;
import java.util.List;
import java.util.List;
import java.util.regex.Pattern;
import java.util.regex.Pattern;


import static android.provider.CalendarContract.EXTRA_EVENT_ALL_DAY;
import static android.provider.CalendarContract.EXTRA_EVENT_BEGIN_TIME;
import static android.provider.CalendarContract.EXTRA_EVENT_END_TIME;
import static com.android.calendar.CalendarController.EVENT_EDIT_ON_LAUNCH;


public class EventInfoFragment extends DialogFragment implements OnCheckedChangeListener,
public class EventInfoFragment extends DialogFragment implements OnCheckedChangeListener,
        CalendarController.EventHandler, OnClickListener, DeleteEventHelper.DeleteNotifyListener {
        CalendarController.EventHandler, OnClickListener, DeleteEventHelper.DeleteNotifyListener {


@@ -167,7 +170,9 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
        Events.HAS_ALARM,            // 14
        Events.HAS_ALARM,            // 14
        Calendars.MAX_REMINDERS,     //15
        Calendars.MAX_REMINDERS,     //15
        Calendars.ALLOWED_REMINDERS, // 16
        Calendars.ALLOWED_REMINDERS, // 16
        Events.ORIGINAL_SYNC_ID,     // 17 do not remove; used in DeleteEventHelper
        Events.CUSTOM_APP_PACKAGE,   // 17
        Events.CUSTOM_APP_URI,       // 18
        Events.ORIGINAL_SYNC_ID,     // 19 do not remove; used in DeleteEventHelper
    };
    };
    private static final int EVENT_INDEX_ID = 0;
    private static final int EVENT_INDEX_ID = 0;
    private static final int EVENT_INDEX_TITLE = 1;
    private static final int EVENT_INDEX_TITLE = 1;
@@ -185,6 +190,8 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
    private static final int EVENT_INDEX_HAS_ALARM = 14;
    private static final int EVENT_INDEX_HAS_ALARM = 14;
    private static final int EVENT_INDEX_MAX_REMINDERS = 15;
    private static final int EVENT_INDEX_MAX_REMINDERS = 15;
    private static final int EVENT_INDEX_ALLOWED_REMINDERS = 16;
    private static final int EVENT_INDEX_ALLOWED_REMINDERS = 16;
    private static final int EVENT_INDEX_CUSTOM_APP_PACKAGE = 17;
    private static final int EVENT_INDEX_CUSTOM_APP_URI = 18;




    private static final String[] ATTENDEES_PROJECTION = new String[] {
    private static final String[] ATTENDEES_PROJECTION = new String[] {
@@ -251,6 +258,8 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange


    private static float mScale = 0; // Used for supporting different screen densities
    private static float mScale = 0; // Used for supporting different screen densities


    private static int mCustomAppIconSize = 32;

    private long mStartMillis;
    private long mStartMillis;
    private long mEndMillis;
    private long mEndMillis;
    private boolean mAllDay;
    private boolean mAllDay;
@@ -494,13 +503,12 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
    public EventInfoFragment(Context context, Uri uri, long startMillis, long endMillis,
    public EventInfoFragment(Context context, Uri uri, long startMillis, long endMillis,
            int attendeeResponse, boolean isDialog, int windowStyle) {
            int attendeeResponse, boolean isDialog, int windowStyle) {


        if (isDialog) {
        Resources r = context.getResources();
        Resources r = context.getResources();


        if (mScale == 0) {
        if (mScale == 0) {
            mScale = context.getResources().getDisplayMetrics().density;
            mScale = context.getResources().getDisplayMetrics().density;
            if (mScale != 1) {
            if (mScale != 1) {
                mCustomAppIconSize *= mScale;
                if (isDialog) {
                    mDialogWidth = r.getInteger(R.integer.event_info_dialog_width);
                    mDialogWidth = r.getInteger(R.integer.event_info_dialog_width);
                    mDialogHeight = r.getInteger(R.integer.event_info_dialog_height);
                    mDialogHeight = r.getInteger(R.integer.event_info_dialog_height);
                    mDialogWidth *= mScale;
                    mDialogWidth *= mScale;
@@ -1218,6 +1226,81 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
            mDesc.setText(description);
            mDesc.setText(description);
        }
        }


        // Launch Custom App
        updateCustomAppButton();
    }

    private void updateCustomAppButton() {
        buttonSetup: {
            final Button launchButton = (Button) mView.findViewById(R.id.launch_custom_app_button);
            if (launchButton == null)
                break buttonSetup;

            final String customAppPackage = mEventCursor.getString(EVENT_INDEX_CUSTOM_APP_PACKAGE);
            final String customAppUri = mEventCursor.getString(EVENT_INDEX_CUSTOM_APP_URI);

            if (TextUtils.isEmpty(customAppPackage) || TextUtils.isEmpty(customAppUri))
                break buttonSetup;

            PackageManager pm = mContext.getPackageManager();
            if (pm == null)
                break buttonSetup;

            ApplicationInfo info;
            try {
                info = pm.getApplicationInfo(customAppPackage, 0);
                if (info == null)
                    break buttonSetup;
            } catch (NameNotFoundException e) {
                break buttonSetup;
            }

            Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, mEventId);
            final Intent intent = new Intent(CalendarContract.ACTION_HANDLE_CUSTOM_EVENT, uri);
            intent.setPackage(customAppPackage);
            intent.putExtra(CalendarContract.EXTRA_CUSTOM_APP_URI, customAppUri);
            intent.putExtra(EXTRA_EVENT_BEGIN_TIME, mStartMillis);

            // See if we have a taker for our intent
            if (pm.resolveActivity(intent, 0) == null)
                break buttonSetup;

            Drawable icon = pm.getApplicationIcon(info);
            if (icon != null) {

                Drawable[] d = launchButton.getCompoundDrawables();
                icon.setBounds(0, 0, mCustomAppIconSize, mCustomAppIconSize);
                launchButton.setCompoundDrawables(icon, d[1], d[2], d[3]);
            }

            CharSequence label = pm.getApplicationLabel(info);
            if (label != null && label.length() != 0) {
                launchButton.setText(label);
            } else if (icon == null) {
                // No icon && no label. Hide button?
                break buttonSetup;
            }

            // Launch custom app
            launchButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    try {
                        startActivityForResult(intent, 0);
                    } catch (ActivityNotFoundException e) {
                        // Shouldn't happen as we checked it already
                        setVisibilityCommon(mView, R.id.launch_custom_app_container, View.GONE);
                    }
                }
            });

            setVisibilityCommon(mView, R.id.launch_custom_app_container, View.VISIBLE);
            return;

        }

        setVisibilityCommon(mView, R.id.launch_custom_app_container, View.GONE);
        return;
    }
    }


    /**
    /**