<commit_before>/*
 * Copyright 2012-2013 eBay Software Foundation and selendroid committers.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package io.selendroid.server.model;


import io.selendroid.ServerInstrumentation;
import io.selendroid.android.AndroidWait;
import io.selendroid.android.KeySender;
import io.selendroid.android.ViewHierarchyAnalyzer;
import io.selendroid.android.internal.Dimension;
import io.selendroid.android.internal.Point;
import io.selendroid.exceptions.ElementNotVisibleException;
import io.selendroid.exceptions.NoSuchElementAttributeException;
import io.selendroid.exceptions.NoSuchElementException;
import io.selendroid.exceptions.SelendroidException;
import io.selendroid.exceptions.TimeoutException;
import io.selendroid.server.model.interactions.AndroidCoordinates;
import io.selendroid.server.model.interactions.Coordinates;
import io.selendroid.server.model.internal.AbstractNativeElementContext;
import io.selendroid.util.Function;
import io.selendroid.util.Preconditions;
import io.selendroid.util.SelendroidLogger;

import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import android.graphics.Rect;
import android.os.SystemClock;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;

public class AndroidNativeElement implements AndroidElement {
  // TODO revisit
  protected static final long DURATION_OF_LONG_PRESS = 750L;// (long)
                                                            // (ViewConfiguration.getLongPressTimeout()
                                                            // * 1.5f);
  private WeakReference<View> viewRef;
  private Collection<AndroidElement> children = new LinkedHashSet<AndroidElement>();
  private AndroidElement parent;
  private ServerInstrumentation instrumentation;
  private final KeySender keys;
  private SearchContext nativeElementSearchScope = null;
  private Coordinates coordinates = null;
  final Object syncObject = new Object();
  private Boolean done = false;
  private KnownElements ke;
  private int hashCode;
  static final long UI_TIMEOUT = 3000L;

  public AndroidNativeElement(View view, ServerInstrumentation instrumentation, KeySender keys,
      KnownElements ke) {
    Preconditions.checkNotNull(view);
    this.viewRef = new WeakReference<View>(view);
    hashCode = view.hashCode() + 31;
    this.instrumentation = instrumentation;
    this.keys = keys;
    this.nativeElementSearchScope = new NativeElementSearchScope(instrumentation, keys, ke);
    this.ke = ke;
  }

  @Override
  public AndroidElement getParent() {
    return parent;
  }

  public boolean isDisplayed() {
    boolean hasWindowFocus = getView().hasWindowFocus();
    boolean enabled = getView().isEnabled();
    int width = getView().getWidth();
    int height = getView().getHeight();
    // In the past we used `getView().isShown()` to identify if the element
    // is displayed. It seems like that it is better to look just at the
    // visibility of the view instead of verifying the ancestors as well.
    boolean isElementDisplayed = View.VISIBLE == getView().getVisibility();

<commit_msg>Fix #268<commit_after>/*
 * Copyright 2012-2013 eBay Software Foundation and selendroid committers.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package io.selendroid.server.model;


import io.selendroid.ServerInstrumentation;
import io.selendroid.android.AndroidWait;
import io.selendroid.android.KeySender;
import io.selendroid.android.ViewHierarchyAnalyzer;
import io.selendroid.android.internal.Dimension;
import io.selendroid.android.internal.Point;
import io.selendroid.exceptions.ElementNotVisibleException;
import io.selendroid.exceptions.NoSuchElementAttributeException;
import io.selendroid.exceptions.NoSuchElementException;
import io.selendroid.exceptions.SelendroidException;
import io.selendroid.exceptions.TimeoutException;
import io.selendroid.server.model.interactions.AndroidCoordinates;
import io.selendroid.server.model.interactions.Coordinates;
import io.selendroid.server.model.internal.AbstractNativeElementContext;
import io.selendroid.util.Function;
import io.selendroid.util.Preconditions;
import io.selendroid.util.SelendroidLogger;

import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import android.graphics.Rect;
import android.os.SystemClock;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;

public class AndroidNativeElement implements AndroidElement {
  // TODO revisit
  protected static final long DURATION_OF_LONG_PRESS = 750L;// (long)
                                                            // (ViewConfiguration.getLongPressTimeout()
                                                            // * 1.5f);
  private WeakReference<View> viewRef;
  private Collection<AndroidElement> children = new LinkedHashSet<AndroidElement>();
  private AndroidElement parent;
  private ServerInstrumentation instrumentation;
  private final KeySender keys;
  private SearchContext nativeElementSearchScope = null;
  private Coordinates coordinates = null;
  final Object syncObject = new Object();
  private Boolean done = false;
  private KnownElements ke;
  private int hashCode;
  static final long UI_TIMEOUT = 3000L;

  public AndroidNativeElement(View view, ServerInstrumentation instrumentation, KeySender keys,
      KnownElements ke) {
    Preconditions.checkNotNull(view);
    this.viewRef = new WeakReference<View>(view);
    hashCode = view.hashCode() + 31;
    this.instrumentation = instrumentation;
    this.keys = keys;
    this.nativeElementSearchScope = new NativeElementSearchScope(instrumentation, keys, ke);
    this.ke = ke;
  }

  @Override
  public AndroidElement getParent() {
    return parent;
  }

  public boolean isDisplayed() {
    boolean hasWindowFocus = getView().hasWindowFocus();
    boolean enabled = getView().isEnabled();
    int width = getView().getWidth();
    int height = getView().getHeight();
    // In the past we used `getView().isShown()` to identify if the element
    // is displayed. It seems like that it is better to look just at the
    // visibility of the view instead of verifying the ancestors as well.
    boolean isElementDisplayed = (View.VISIBLE == getView().getVisibility())
        && getView().isShown();


{'fraction_non_alphanumeric': 0.08366238894373149, 'fraction_numerical': 0.00604639684106614, 'mean_word_length': 4.280130293159609, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6276232', 'n_tokens_mistral': 2202, 'n_tokens_neox': 2116, 'n_words': 624}