Skip to content

Commit

Permalink
Merge branch '7_1_X' into TIMOB-20522_71X
Browse files Browse the repository at this point in the history
  • Loading branch information
garymathews authored Feb 21, 2018
2 parents c95e3b5 + 051d260 commit f745031
Show file tree
Hide file tree
Showing 7 changed files with 376 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ public TiUIDrawerLayout(final DrawerLayoutProxy proxy)
this.activity = (AppCompatActivity) proxy.getActivity();
LayoutInflater inflater = LayoutInflater.from(this.activity);
layout = (DrawerLayout) inflater.inflate(id_drawer_layout, null, false);
layout.setDrawerListener(new DrawerListener());
toolbar = (Toolbar) layout.findViewById(id_toolbar);

// Check if the theme provides a default ActionBar
Expand Down Expand Up @@ -165,34 +164,6 @@ private void drawerSlideEvent(View drawerView, float slideOffset)
}
}

private class DrawerListener implements DrawerLayout.DrawerListener
{

@Override
public void onDrawerClosed(View drawerView)
{
drawerClosedEvent(drawerView);
}

@Override
public void onDrawerOpened(View drawerView)
{
drawerOpenedEvent(drawerView);
}

@Override
public void onDrawerSlide(View drawerView, float slideOffset)
{
drawerSlideEvent(drawerView, slideOffset);
}

@Override
public void onDrawerStateChanged(int state)
{
drawerStateChangedEvent(state);
}
}

public void toggleLeft()
{
if (layout.isDrawerOpen(Gravity.START)) {
Expand Down Expand Up @@ -254,40 +225,45 @@ public boolean isRightVisible()
private void initDrawerToggle()
{

AppCompatActivity activity = (AppCompatActivity) proxy.getActivity();
if (activity.getSupportActionBar() == null) {
final AppCompatActivity activity = (AppCompatActivity) proxy.getActivity();
if (activity == null) {
return;
}

activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
activity.getSupportActionBar().setHomeButtonEnabled(true);
if (activity.getSupportActionBar() != null) {
activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
activity.getSupportActionBar().setHomeButtonEnabled(true);
}

drawerToggle = new ActionBarDrawerToggle(activity, layout, id_drawer_open_string, id_drawer_close_string) {
@Override
public void onDrawerClosed(View drawerView)
{
super.onDrawerClosed(drawerView);
drawerClosedEvent(drawerView);
}

@Override
public void onDrawerOpened(View drawerView)
{
super.onDrawerOpened(drawerView);
drawerOpenedEvent(drawerView);
}

@Override
public void onDrawerSlide(View drawerView, float slideOffset)
{
super.onDrawerSlide(drawerView, slideOffset);
drawerSlideEvent(drawerView, slideOffset);
}

@Override
public void onDrawerStateChanged(int state)
{
super.onDrawerStateChanged(state);
drawerStateChangedEvent(state);
}
};
layout.setDrawerListener(drawerToggle);
layout.addDrawerListener(drawerToggle);
layout.post(new Runnable() {
@Override
public void run()
Expand Down Expand Up @@ -586,7 +562,7 @@ public void release()
{
if (layout != null) {
layout.removeAllViews();
layout.setDrawerListener(null);
layout.removeDrawerListener(drawerToggle);
layout = null;
}
if (leftFrame != null) {
Expand Down Expand Up @@ -625,7 +601,9 @@ private int getDevicePixels(Object value)

private View getNativeView(TiViewProxy viewProxy)
{
View nativeView = viewProxy.getOrCreateView().getOuterView();
TiUIView view = viewProxy.getOrCreateView();
View outerView = view.getOuterView();
View nativeView = outerView != null ? outerView : view.getNativeView();
ViewGroup parentViewGroup = (ViewGroup) nativeView.getParent();
if (parentViewGroup != null) {
parentViewGroup.removeAllViews();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
import android.widget.Spinner;
import android.widget.TextView;

public class TiUINativePicker extends TiUIPicker implements OnItemSelectedListener
public class TiUINativePicker extends TiUIPicker
{
private static final String TAG = "TiUINativePicker";
private boolean firstSelectedFired = false;
private boolean nativeViewDrawn = false;
private static int defaultTextColor;
private static boolean setDefaultTextColor = false;

Expand Down Expand Up @@ -101,7 +101,6 @@ public TiUINativePicker(TiViewProxy proxy)
public TiUINativePicker(final TiViewProxy proxy, Activity activity)
{
this(proxy);

int spinnerId;
try {
spinnerId = TiRHelper.getResource("layout.titanium_ui_spinner");
Expand All @@ -111,14 +110,19 @@ public TiUINativePicker(final TiViewProxy proxy, Activity activity)
}
return;
}
Spinner spinner = (Spinner) activity.getLayoutInflater().inflate(spinnerId, null);
final Spinner spinner = (Spinner) activity.getLayoutInflater().inflate(spinnerId, null);

spinner.addOnLayoutChangeListener(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)
{
TiUIHelper.firePostLayoutEvent(proxy);
// Set the flag showing if the native view has been drawn
nativeViewDrawn = true;
// Attach the listener for the first time after
// all the setting up has finished.
spinner.setOnItemSelectedListener(onItemSelectedListener);
}
});

Expand All @@ -139,31 +143,23 @@ public boolean onTouch(View v, MotionEvent event)
setNativeView(spinner);
refreshNativeView();
preselectRows();

spinner.setOnItemSelectedListener(this);
}

private void preselectRows()
{
Spinner spinner = (Spinner) nativeView;
ArrayList<Integer> preselectedRows = getPickerProxy().getPreselectedRows();
if (preselectedRows == null || preselectedRows.size() == 0) {
return;
}
Spinner spinner = (Spinner) nativeView;
if (spinner == null)
return;
try {
spinner.setOnItemSelectedListener(null);
for (int i = 0; i < preselectedRows.size(); i++) {
Integer rowIndex = preselectedRows.get(i);
if (rowIndex == 0 || rowIndex.intValue() < 0) {
continue;
}
selectRow(i, rowIndex, false);
for (int i = 0; i < preselectedRows.size(); i++) {
Integer rowIndex = preselectedRows.get(i);
if (rowIndex == 0 || rowIndex.intValue() < 0) {
continue;
}
} finally {
spinner.setOnItemSelectedListener(this);
firstSelectedFired = true;
selectRow(i, rowIndex, false);
}
}

Expand Down Expand Up @@ -205,13 +201,17 @@ public int getSelectedRowIndex(int columnIndex)
protected void refreshNativeView()
{
// Don't allow change events here
suppressChangeEvent = true;
Spinner spinner = (Spinner) nativeView;
if (spinner == null) {
return;
}
try {
spinner.setOnItemSelectedListener(null);
if (nativeViewDrawn) {
// If we have drawn the spinner it has a selected item listener.
// Detach while the native view is refreshed to prevent
// unnecessary event triggers.
spinner.setOnItemSelectedListener(null);
}
int rememberSelectedRow = getSelectedRowIndex(0);
// Just one column - the first column - for now.
// Maybe someday we'll support multiple columns.
Expand All @@ -237,39 +237,37 @@ protected void refreshNativeView()
if (rememberSelectedRow >= 0) {
selectRow(0, rememberSelectedRow, false);
}

// The new adapter has been set.
// If the Spinner has been drawn reattach the onItemSelected listener here.
// If it has not been drawn yet, the listener will be attached in the
// onLayout lifecycle event.
if (nativeViewDrawn) {
spinner.setOnItemSelectedListener(onItemSelectedListener);
}
} catch (Throwable t) {
Log.e(TAG, "Unable to refresh native spinner control: " + t.getMessage(), t);
} finally {
suppressChangeEvent = false;
spinner.setOnItemSelectedListener(this);
}
}

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long itemId)
{
if (!firstSelectedFired) {
// swallow the first selected event that gets fired after the adapter gets set, so as to avoid
// firing our change event in that case.
firstSelectedFired = true;
return;
}
fireSelectionChange(0, position);
private final OnItemSelectedListener onItemSelectedListener = new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long itemId)
{
fireSelectionChange(0, position);

// Invalidate the parent view after the item is selected (TIMOB-13540).
if (Build.VERSION.SDK_INT >= TiC.API_LEVEL_HONEYCOMB) {
// Invalidate the parent view after the item is selected (TIMOB-13540).
ViewParent p = nativeView.getParent();
if (p instanceof View) {
((View) p).invalidate();
}
}
}

@Override
public void onNothingSelected(AdapterView<?> arg0)
{
}
@Override
public void onNothingSelected(AdapterView<?> parent)
{
}
};

public void add(TiUIView child)
{
// Don't do anything. We don't add/remove views to the native picker (the Android "Spinner").
Expand Down Expand Up @@ -324,4 +322,4 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
super.propertyChanged(key, oldValue, newValue, proxy);
}
}
}
}
3 changes: 2 additions & 1 deletion android/templates/build/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.appcelerator.kroll.runtime.v8.V8Runtime;

import org.appcelerator.kroll.KrollExternalModule;
import org.appcelerator.kroll.common.KrollSourceCodeProvider;
import org.appcelerator.kroll.KrollModule;
import org.appcelerator.kroll.KrollModuleInfo;
import org.appcelerator.kroll.KrollRuntime;
Expand Down Expand Up @@ -62,7 +63,7 @@ public void onCreate()
try {
runtime.addExternalCommonJsModule(
"<%- module.manifest.moduleid %>",
(Class<KrollExternalModule>) Class.forName(className));
(Class<KrollSourceCodeProvider>) Class.forName(className));
} catch (Throwable ex) {
Log.e(TAG, "Failed to add external CommonJS module: " + className);
if ((ex instanceof RuntimeException) == false) {
Expand Down
4 changes: 3 additions & 1 deletion apidoc/Titanium/UI/Picker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ methods:

- name: setSelectedRow
summary: Selects a column's row.
description: On iOS, this method must be called after the picker is rendered.
description: |
On iOS, this method must be called after the picker is rendered.
On Android, the picker has a default value of 0 for both column and row index.
parameters:
- name: column
summary: A column index.
Expand Down
39 changes: 23 additions & 16 deletions package-lock.json

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

Loading

0 comments on commit f745031

Please sign in to comment.