Skip to content

Commit

Permalink
Merge branch 'master' into androidListViewLayout
Browse files Browse the repository at this point in the history
  • Loading branch information
m1ga authored Jul 3, 2024
2 parents eb66896 + 420ccdc commit c1faa6b
Show file tree
Hide file tree
Showing 18 changed files with 344 additions and 81 deletions.
20 changes: 17 additions & 3 deletions android/.idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ android.useAndroidX=true
android.enableJetifier=false

# remove if com.android.tools.build:gradle can be raised in /android/build.gradle
android.suppressUnsupportedCompileSdk=33
android.suppressUnsupportedCompileSdk=33,34
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,14 @@ public void registerBroadcastReceiver(BroadcastReceiverProxy receiverProxy, Obje
filter.addAction(TiConvert.toString(action));
}

TiApplication.getInstance().registerReceiver(receiverProxy.getBroadcastReceiver(), filter);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU
&& TiApplication.getInstance().getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.TIRAMISU) {
int receiverFlags = Context.RECEIVER_EXPORTED;
TiApplication.getInstance().registerReceiver(
receiverProxy.getBroadcastReceiver(), filter, receiverFlags);
} else {
TiApplication.getInstance().registerReceiver(receiverProxy.getBroadcastReceiver(), filter);
}
if (this.registeredBroadcastReceiverProxyList.contains(receiverProxy) == false) {
this.registeredBroadcastReceiverProxyList.add(receiverProxy);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
package ti.modules.titanium.network;

import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.TiApplication;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
Expand Down Expand Up @@ -110,7 +112,13 @@ public void attach(Context context)
} else {
throw new IllegalStateException("Context was not cleaned up from last release.");
}
context.registerReceiver(receiver, connectivityIntentFilter);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU
&& TiApplication.getInstance().getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.TIRAMISU) {
int receiverFlags = Context.RECEIVER_EXPORTED;
context.registerReceiver(receiver, connectivityIntentFilter, receiverFlags);
} else {
context.registerReceiver(receiver, connectivityIntentFilter);
}
listening = true;
} else {
Log.w(TAG, "Connectivity listener is already attached");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
TiC.PROPERTY_COLOR,
TiC.PROPERTY_FONT,
TiC.PROPERTY_TEXT_ALIGN,
TiC.PROPERTY_VERTICAL_ALIGN
TiC.PROPERTY_TINT_COLOR,
TiC.PROPERTY_ON_TINT_COLOR,
TiC.PROPERTY_VERTICAL_ALIGN,
TiC.PROPERTY_ON_THUMB_COLOR,
TiC.PROPERTY_THUMB_COLOR
})
public class SwitchProxy extends TiViewProxy
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
package ti.modules.titanium.ui.widget;

import android.app.Activity;
import android.content.res.ColorStateList;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

import androidx.appcompat.widget.AppCompatToggleButton;

import com.google.android.material.checkbox.MaterialCheckBox;
import com.google.android.material.chip.Chip;
import com.google.android.material.switchmaterial.SwitchMaterial;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.common.Log;
Expand All @@ -23,21 +27,23 @@
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiUIView;

import ti.modules.titanium.ui.UIModule;

public class TiUISwitch extends TiUIView implements OnCheckedChangeListener
{
private static final String TAG = "TiUISwitch";

private View.OnLayoutChangeListener layoutListener;
private final View.OnLayoutChangeListener layoutListener;
private boolean oldValue = false;

public TiUISwitch(TiViewProxy proxy)
{
super(proxy);
Log.d(TAG, "Creating a switch", Log.DEBUG_MODE);

this.layoutListener = new View.OnLayoutChangeListener() {
this.layoutListener = new View.OnLayoutChangeListener()
{
@Override
public void onLayoutChange(
View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom)
Expand All @@ -58,6 +64,62 @@ public void processProperties(KrollDict d)
setStyle(TiConvert.toInt(d.get(TiC.PROPERTY_STYLE), UIModule.SWITCH_STYLE_SLIDER));
}

if (d.containsKeyAndNotNull(TiC.PROPERTY_THUMB_COLOR)
|| d.containsKeyAndNotNull(TiC.PROPERTY_ON_THUMB_COLOR)) {
CompoundButton currentButton = (CompoundButton) getNativeView();
if (currentButton instanceof SwitchMaterial) {

int colActive = d.containsKeyAndNotNull(TiC.PROPERTY_ON_THUMB_COLOR)
? TiConvert.toColor(d, TiC.PROPERTY_ON_THUMB_COLOR)
: TiConvert.toColor(d, TiC.PROPERTY_THUMB_COLOR);
int colNormal = d.containsKeyAndNotNull(TiC.PROPERTY_THUMB_COLOR)
? TiConvert.toColor(d, TiC.PROPERTY_THUMB_COLOR)
: TiConvert.toColor(d, TiC.PROPERTY_ON_THUMB_COLOR);

ColorStateList trackStates = new ColorStateList(
new int[][] {
new int[] { -android.R.attr.state_enabled },
new int[] { android.R.attr.state_checked },
new int[] {}
},
new int[] {
colNormal,
colActive,
colNormal
}
);
((SwitchMaterial) currentButton).setThumbTintList(trackStates);
}
}

if (d.containsKeyAndNotNull(TiC.PROPERTY_TINT_COLOR)
|| d.containsKeyAndNotNull(TiC.PROPERTY_ON_TINT_COLOR)) {
CompoundButton currentButton = (CompoundButton) getNativeView();
if (currentButton instanceof SwitchMaterial) {

int colActive = d.containsKeyAndNotNull(TiC.PROPERTY_ON_TINT_COLOR)
? TiConvert.toColor(d, TiC.PROPERTY_ON_TINT_COLOR)
: TiConvert.toColor(d, TiC.PROPERTY_TINT_COLOR);
int colNormal = d.containsKeyAndNotNull(TiC.PROPERTY_TINT_COLOR)
? TiConvert.toColor(d, TiC.PROPERTY_TINT_COLOR)
: TiConvert.toColor(d, TiC.PROPERTY_ON_TINT_COLOR);

ColorStateList trackStates = new ColorStateList(
new int[][] {
new int[] { -android.R.attr.state_enabled },
new int[] { android.R.attr.state_checked },
new int[] {}
},
new int[] {
colNormal,
colActive,
colNormal
}
);
((SwitchMaterial) currentButton).setTrackTintList(trackStates);
}
}

if (d.containsKey(TiC.PROPERTY_VALUE)) {
oldValue = TiConvert.toBoolean(d, TiC.PROPERTY_VALUE);
}
Expand Down Expand Up @@ -151,7 +213,7 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
} else {
super.propertyChanged(key, oldValue, newValue, proxy);
}
}
}

@Override
public void onCheckedChanged(CompoundButton btn, boolean value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Looper;
import android.os.SystemClock;
import android.util.DisplayMetrics;
Expand Down Expand Up @@ -961,7 +962,13 @@ public void onReceive(Context context, Intent intent)
}
};

registerReceiver(localeReceiver, new IntentFilter(Intent.ACTION_LOCALE_CHANGED));
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU
&& TiApplication.getInstance().getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.TIRAMISU) {
int receiverFlags = Context.RECEIVER_EXPORTED;
registerReceiver(localeReceiver, new IntentFilter(Intent.ACTION_LOCALE_CHANGED), receiverFlags);
} else {
registerReceiver(localeReceiver, new IntentFilter(Intent.ACTION_LOCALE_CHANGED));
}
}

private void stopLocaleMonitor()
Expand Down
3 changes: 3 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ public class TiC
public static final String EVENT_PROPERTY_TAB = "tab";
public static final String EVENT_PROPERTY_THUMB_OFFSET = "thumbOffset";
public static final String EVENT_PROPERTY_THUMB_SIZE = "thumbSize";
public static final String PROPERTY_THUMB_COLOR = "thumbColor";
public static final String PROPERTY_ON_THUMB_COLOR = "onThumbColor";
public static final String EVENT_PROPERTY_TYPE = "type";
public static final String EVENT_PROPERTY_VELOCITY = "velocity";
public static final String EVENT_PROPERTY_X = "x";
Expand Down Expand Up @@ -608,6 +610,7 @@ public class TiC
public static final String PROPERTY_ON_RESTART = "onRestart";
public static final String PROPERTY_ON_PAUSE = "onPause";
public static final String PROPERTY_ON_STOP = "onStop";
public static final String PROPERTY_ON_TINT_COLOR = "onTintColor";
public static final String PROPERTY_TLS_VERSION = "tlsVersion";
public static final String PROPERTY_ON_DESTROY = "onDestroy";
public static final String PROPERTY_ON_CREATE_WINDOW = "onCreateWindow";
Expand Down
29 changes: 27 additions & 2 deletions apidoc/Titanium/UI/ListItem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -674,12 +674,27 @@ properties:
---
name: RowActionType
summary: Represents the custom edit action for a ListItem.
summary: Represents the custom edit action for a ListItem or TableViewRow.
description: |
By default when a listItem has [canEdit](Titanium.UI.ListItem.canEdit) set to true, a left swipe on the the row presens the 'Delete' button.
Edit actions can be used to add contextual buttons to your list items / table view rows. The configuration of
this API is the same for list items (if you use <Titanium.UI.ListView>) and table view rows (if you use <Titanium.UI.TableView).
But please note that the trigger to activate these edit actions can defer based on the API you're integrating the edit actions:
*List Views*:
By default when a ListItem has [canEdit](Titanium.UI.ListItem.canEdit) set to `true`, a left swipe on the the row presens the localized 'Delete' button.
This object lets developers define custom titles for editing actions supported on the row.
This object is used in conjunction with the [editActions](Titanium.UI.ListItem.editActions) property and
[editaction](Titanium.UI.ListView.editaction) event.
*Table Views*:
By default when a TableViewRow has [editable](Titanium.UI.TableViewRow.editable) set to `true`, a left swipe on the the row presens the localized 'Delete' button.
This object lets developers define custom titles for editing actions supported on the row.
This object is used in conjunction with the [editActions](Titanium.UI.TableViewRow.editActions) property and
[editaction](Titanium.UI.TableView.editaction) event. For table views, this property was added in Titanium SDK 12.4.0.
In addition, the new property "state" was added in 12.4.0 and can either equal "leading" or "trailing" to show them on a right swipe (leading)
or left swipe (trailing). If the "state" property is not set, it defaults to "trailing" for backwards compatibility.
platforms: [ipad, iphone, macos]
since: '4.1.0'
properties:
Expand Down Expand Up @@ -719,3 +734,13 @@ properties:
optional: true
since: 12.1.0
platforms: [iphone, ipad, macos]

- name: state
type: String
summary: The state to show this edit action. Either "trailing" (default) or "leading".
description: |
In a LTR layout (e.g English, German), the "leading" state is the left area of the screen and the "trailing" state in the right.
In a RTL layout (e.g. Hebrew, Arabic), the "leading" state is the right area of the screen and the "trailing" state in the left.
optional: true
since: 12.4.0
platforms: [iphone, ipad, macos]
32 changes: 28 additions & 4 deletions apidoc/Titanium/UI/Switch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,41 @@ properties:

- name: tintColor
summary: The color used to tint the outline of the switch when it is turned off.
description: |
The color used to tint the outline of the switch when it is turned off.
Android: Track color of the Material Switch.
type: [String, Titanium.UI.Color]
default: undefined
platforms: [iphone, ipad, macos]
since: "3.3.0"
platforms: [android, iphone, ipad]
since: {android: 12.4.0, iphone: 3.3.0, ipad: 3.3.0}

- name: onThumbColor
description: |
The color used to tint the thumb icon of the switch when it is turned on.
Android: Active thumb color of the Material Switch.
type: [String, Titanium.UI.Color]
default: undefined
platforms: [android]
since: {android: 12.4.0}

- name: thumbColor
description: |
The color used to tint the thumb icon of the switch when it is turned off.
Android: Inactive thumb color of the Material Switch.
type: [String, Titanium.UI.Color]
default: undefined
platforms: [android]
since: {android: 12.4.0}

- name: onTintColor
summary: The color used to tint the appearance of the switch when it is turned on.
type: [String, Titanium.UI.Color]
default: undefined
platforms: [iphone, ipad, macos]
since: "3.3.0"
platforms: [android, iphone, ipad, macos]
since: {android: 12.4.0, iphone: 3.3.0, ipad: 3.3.0}

- name: thumbTintColor
summary: The color used to tint the appearance of the thumb.
Expand Down
34 changes: 34 additions & 0 deletions apidoc/Titanium/UI/TableView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,40 @@ events:
type: Boolean
since: '3.0.0'

- name: editaction
summary: Fired when the user interacts with one of the custom edit actions defined by <Titanium.UI.TableViewRow.editActions>.
description: |
Do not rely on the `source` property to determine which item fired the event. Use the
`row` and `section`, or the `index` to determine the table row that generated
the event.
Note that the `index` property of this event correspond to the list view state
before the user action.
platforms: [iphone, ipad, macos]
since: 12.4.0
properties:
- name: action
summary: The [title](RowActionType.title) as defined in the row action object.
type: String

- name: identifier
summary: |
The [identifier](RowActionType. identifier) of the row action. Only included in the event
if previously defined.
type: String

- name: row
summary: The row that fired this event.
type: [Titanium.UI.TableViewRow, Dictionary<Titanium.UI.TableViewRow>]

- name: section
summary: The section that fired this event.
type: Titanium.UI.TableViewSection

- name: index
summary: The index of the row that fired this event.
type: Number

methods:
- name: appendRow
summary: Appends a single row or an array of rows to the end of the table.
Expand Down
Loading

0 comments on commit c1faa6b

Please sign in to comment.