Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): collapse toolbar menu support #14093

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
f31e0b7
feat(android): add keyboard show/hide event
m1ga Jan 21, 2023
64b4ece
docs
m1ga Jan 21, 2023
a2ee315
use Android version
m1ga Jan 21, 2023
0a9c121
move to app event
m1ga Jan 23, 2023
21dab2a
move to app event
m1ga Jan 23, 2023
89fe70f
size return value
m1ga Jan 23, 2023
88d11b9
check for listener
m1ga Jan 24, 2023
c161d9f
remove extra check, simplify if statement
m1ga Jan 24, 2023
dc213e3
some more null checks for safety
m1ga Jan 24, 2023
ea52729
lint
m1ga Jan 24, 2023
fec7cc7
hasListener check
m1ga Jan 24, 2023
8e75df1
check app listener in safearea
m1ga Feb 6, 2023
0ccd1c8
kotlin 1.8.10, ios logging
Max87ZA May 9, 2023
927899a
feat: add spring animations
hansemannn Aug 1, 2023
9632aa5
Merge branch 'master' into feature/ios17-spring-animations
hansemannn Aug 4, 2023
673b2ab
Merge pull request #1 from tidev/master
Max87ZA Aug 4, 2023
9cfb8f9
(fix):network client fix
Max87ZA Aug 4, 2023
88867b7
network client fix
Max87ZA Aug 4, 2023
86099b6
Merge branch 'master' into kotlin_1810
Max87ZA Aug 9, 2023
dd1c144
Merge pull request #2 from Max87ZA/kotlin_1810
Max87ZA Aug 9, 2023
43d2dc5
feat(ios): largeTitleAttributes
Max87ZA Aug 9, 2023
2fbe62b
feat(ios): largeTitleAttributes
Max87ZA Aug 9, 2023
b012d46
feat(ios): largeTitleAttributes
Max87ZA Aug 9, 2023
ebb3917
fix(ios): removed commented code
Max87ZA Aug 10, 2023
fd3c8d6
Update android/modules/network/src/java/ti/modules/titanium/network/T…
m1ga Sep 22, 2023
9275941
Merge branch 'tidev:master' into master
Max87ZA Oct 29, 2023
ef366cb
Merge branch 'feat(ios)largeTitleAttributes'
Max87ZA Oct 29, 2023
6129990
fix(ios): removed setLargeTitleAttributes duplicity
Max87ZA Oct 29, 2023
cfa58ed
feat(ios): added logging with timestamp
Max87ZA Oct 29, 2023
c84ca1c
feat: support multi-scene applications
hansemannn Oct 31, 2023
13d4e71
feat(ios): largeTitleAttributes added
Max87ZA Nov 1, 2023
10cfeee
Merge remote-tracking branch 'upstream/feature/support-scenes'
Max87ZA Nov 1, 2023
f6e78cc
revert changes from hans
Max87ZA Nov 1, 2023
e3987fd
Merge branch 'master' into 230121_keyboard_hide_event
m1ga Dec 25, 2023
1c19345
Update apidoc/Titanium/App/App.yml
m1ga Dec 25, 2023
a816eed
Update apidoc/Titanium/App/App.yml
m1ga Dec 25, 2023
0bbe7a2
Merge pull request #3 from tidev/master
Max87ZA Apr 26, 2024
f252d02
feat(ios): add timestamp to console's log
May 22, 2024
73bd156
feat(ios): feat(ios): add overrideUserInterfaceStyle to Picker
May 22, 2024
3a344c3
Merge branch 'master' into 230121_keyboard_hide_event
m1ga Jun 10, 2024
bf5695a
Merge branch 'tidev_master'
Jun 10, 2024
3c3512c
Merge branch '230121_keyboard_hide_event'
Jun 10, 2024
48709a1
feat(android): collapse toolbar menu support
Max87ZA Aug 6, 2024
16d7740
build: merge 'tidev/master'
Max87ZA Aug 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.ITiAppInfo;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiBaseActivity;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiSensorHelper;
Expand Down Expand Up @@ -155,6 +156,16 @@ public boolean getAccessibilityEnabled()
return TiApplication.getInstance().getAccessibilityManager().isEnabled();
}

@Kroll.getProperty
public boolean getKeyboardVisible()
{
TiBaseActivity activity = (TiBaseActivity) TiApplication.getAppCurrentActivity();
if (activity == null) {
return false;
}
return TiConvert.toBoolean(activity.keyboardVisible, false);
}

@Kroll.method(name = "_restart")
public void restart()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
android:id="@+id/collapseToolbarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|snap|exitUntilCollapsed">
app:layout_scrollFlags="scroll|snap|exitUntilCollapsed"
app:titleCentered="true"
app:collapsedTitleGravity="center|center_horizontal">

<ImageView
android:id="@+id/collapseImageView"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false">

<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<org.appcelerator.titanium.view.TiCompositeLayout
android:id="@+id/collapseContent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- main content -->
</org.appcelerator.titanium.view.TiCompositeLayout>

</androidx.core.widget.NestedScrollView>

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- toolbar -->

<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapseToolbarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|snap|exitUntilCollapsed"
app:titleCentered="true"
app:collapsedTitleGravity="center|center_horizontal">

<ImageView
android:id="@+id/collapseImageView"
android:layout_width="match_parent"
android:layout_height="250dp"
android:scaleType="centerCrop"
android:visibility="invisible"
app:layout_collapseMode="parallax" />

<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:titleCentered="true"/>

</com.google.android.material.appbar.CollapsingToolbarLayout>

</com.google.android.material.appbar.AppBarLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,29 @@ public void setNavigationIconColor(String value)
{
collapseToolbar.setNavigationIconColor(TiConvert.toColor(value, TiApplication.getAppCurrentActivity()));
}

@Kroll.method
public void addMenuItem(int itemId, String title, boolean showAsAction)
{
// int iconResId = TiDrawableReference.fromObject(this, iconPath).getBitmap(false)
collapseToolbar.addMenuItem(itemId, title, showAsAction);
}

@Kroll.method
public void removeMenuItem(int itemId)
{
collapseToolbar.removeMenuItem(itemId);
}

@Kroll.method
public void clearMenu()
{
collapseToolbar.clearMenu();
}

@Kroll.method
public void setOnMenuItemClickListener(KrollFunction function)
{
collapseToolbar.setOnMenuItemClickListener(function);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.ImageView;
import android.view.Menu;
import android.view.MenuItem;

import androidx.coordinatorlayout.widget.CoordinatorLayout;

Expand Down Expand Up @@ -49,9 +51,10 @@ public class TiUICollapseToolbar extends TiUIView
ImageView imageView = null;
MaterialToolbar toolbar = null;
KrollFunction homeIconFunction = null;
KrollFunction menuItemClickFunction = null;
boolean homeAsUp = false;
TiViewProxy localContentView = null;

public TiUICollapseToolbar(TiViewProxy proxy)
{
super(proxy);
Expand Down Expand Up @@ -257,4 +260,49 @@ public void processProperties(KrollDict d)
setNavigationIconColor(TiConvert.toColor(d.getString(TiC.PROPERTY_NAVIGATION_ICON_COLOR), activity));
}
}
public void addMenuItem(int itemId, String title, boolean showAsAction)
{
if (toolbar != null) {
Menu menu = toolbar.getMenu();
MenuItem item = menu.add(Menu.NONE, itemId, Menu.NONE, title);
// item.setIcon(iconResId);
item.setShowAsAction(showAsAction ? MenuItem.SHOW_AS_ACTION_ALWAYS : MenuItem.SHOW_AS_ACTION_NEVER);
}
}

public void removeMenuItem(int itemId)
{
if (toolbar != null) {
Menu menu = toolbar.getMenu();
MenuItem item = menu.findItem(itemId);
if (item != null) {
menu.removeItem(itemId);
}
}
}

public void clearMenu()
{
if (toolbar != null) {
Menu menu = toolbar.getMenu();
menu.clear();
}
}
public void setOnMenuItemClickListener(KrollFunction value)
{
Log.d(TAG, "inside setOnMenuItemClickListener");
this.menuItemClickFunction = value;
if (toolbar != null) {
toolbar.setOnMenuItemClickListener(item -> {
Log.d(TAG, "inside toolbar.setOnMenuItemClickListener");

if (menuItemClickFunction != null) {
KrollDict event = new KrollDict();
event.put("menuItemId", item.getItemId());
menuItemClickFunction.callAsync(proxy.getKrollObject(), new Object[]{event});
}
return true;
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,21 @@ public void removeAppEventProxy(KrollProxy appEventProxy)
appEventProxies.remove(appEventProxy);
}

public boolean hasListener(String eventName)
{
for (WeakReference<KrollProxy> weakProxy : appEventProxies) {
KrollProxy appEventProxy = weakProxy.get();
if (appEventProxy == null) {
continue;
}
if (appEventProxy.hasListeners(eventName)) {
return true;
}

}
return false;
}

public boolean fireAppEvent(String eventName, KrollDict data)
{
boolean handled = false;
Expand All @@ -679,7 +694,6 @@ public boolean fireAppEvent(String eventName, KrollDict data)
if (appEventProxy == null) {
continue;
}

boolean proxyHandled = appEventProxy.fireEvent(eventName, data);
handled = handled || proxyHandled;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Insets;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.os.Build;
Expand Down Expand Up @@ -106,6 +107,7 @@ public abstract class TiBaseActivity extends AppCompatActivity implements TiActi
private TiActionBarStyleHandler actionBarStyleHandler;
private TiActivitySafeAreaMonitor safeAreaMonitor;
private Context baseContext;
public boolean keyboardVisible = false;
/**
* Callback to be invoked when the TiBaseActivity.onRequestPermissionsResult() has been called,
* providing the results of a requestPermissions() call. Instances of this interface are to
Expand Down Expand Up @@ -674,7 +676,11 @@ protected void onCreate(Bundle savedInstanceState)

this.inForeground = true;
this.launchIntent = getIntent();
this.safeAreaMonitor = new TiActivitySafeAreaMonitor(this);

TiApplication tiApp = getTiApp();
TiApplication.addToActivityStack(this);

this.safeAreaMonitor = new TiActivitySafeAreaMonitor(this, tiApp);

// Fetch the current UI mode flags. Used to determine light/dark theme being used.
Configuration config = getResources().getConfiguration();
Expand All @@ -695,9 +701,6 @@ protected void onCreate(Bundle savedInstanceState)
}
}

TiApplication tiApp = getTiApp();
TiApplication.addToActivityStack(this);

// Increment the Titanium activity reference count. To be decremented in onDestroy() method.
// Titanium's JavaScript runtime is created when we have at least 1 activity and destroyed when we have 0.
KrollRuntime.incrementActivityRefCount();
Expand Down Expand Up @@ -787,6 +790,34 @@ public void onChanged(TiActivitySafeAreaMonitor monitor)
windowProxy.fireSafeAreaChangedEvent();
}
}

@Override
public void onKeyboardChanged(boolean isVisible, int width, int height, Insets keyboardSize)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
&& isVisible != keyboardVisible
&& tiApp != null
&& tiApp.hasListener("keyboardframechanged")) {
KrollDict kdAll = new KrollDict();
KrollDict kdFrame = new KrollDict();

KrollDict kdX = new KrollDict();
kdX.put("left", keyboardSize.left);
kdX.put("right", keyboardSize.right);

KrollDict kdY = new KrollDict();
kdX.put("top", keyboardSize.top);
kdX.put("bottom", keyboardSize.bottom);
kdFrame.put("x", kdX);
kdFrame.put("y", kdY);
kdFrame.put("height", keyboardSize.bottom);
kdFrame.put("width", width - keyboardSize.left - keyboardSize.right);
kdAll.put("keyboardFrame", kdFrame);
kdAll.put("animationDuration", 0);
tiApp.fireAppEvent("keyboardframechanged", kdAll);
keyboardVisible = isVisible;
}
}
});
this.safeAreaMonitor.start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@

package org.appcelerator.titanium.view;

import android.graphics.Insets;
import android.graphics.Rect;
import android.os.Build;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import android.view.View;
import android.view.Window;
import android.view.WindowInsets;

import org.appcelerator.titanium.TiApplication;

import java.util.ArrayList;

/** Tracks safe-area inset changes for a given activity. */
Expand All @@ -27,6 +32,7 @@ public class TiActivitySafeAreaMonitor
*/
public interface OnChangedListener {
void onChanged(TiActivitySafeAreaMonitor monitor);
void onKeyboardChanged(boolean keyboardVisible, int width, int height, Insets keyboardSize);
}

/** The activity to be monitored. */
Expand Down Expand Up @@ -68,18 +74,21 @@ public interface OnChangedListener {
/** Region between the screen insets in pixels, relative to the root decor view. */
private Rect safeArea;

private TiApplication tiApp;

/**
* Creates an object used to track safe-area region changes for the given activity.
* @param activity The activity to be monitored. Cannot be null.
*/
public TiActivitySafeAreaMonitor(AppCompatActivity activity)
public TiActivitySafeAreaMonitor(AppCompatActivity activity, TiApplication app)
{
// Validate.
if (activity == null) {
throw new NullPointerException();
}

// Initialize member variables.
this.tiApp = app;
this.activity = activity;
this.isActionBarAddedAsInset = true;
this.insetsProviderCollection = new ArrayList<>(8);
Expand All @@ -105,6 +114,17 @@ public void onLayoutChange(View view, int left, int top, int right, int bottom,
@Override
public WindowInsets onApplyWindowInsets(View view, WindowInsets insets)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
&& tiApp != null
&& tiApp.hasListener("keyboardframechanged")
) {
boolean keyboardVisible = insets.isVisible(WindowInsets.Type.ime());
Insets keyboardSize = insets.getInsets(WindowInsets.Type.ime());
if (changeListener != null && view != null) {
changeListener.onKeyboardChanged(keyboardVisible, view.getWidth(),
view.getHeight(), keyboardSize);
}
}
// Validate.
if (view == null) {
return insets;
Expand Down
Loading