예제 #1
1
  public void testRemoveOnGlobalFocusChangeListener() {
    final LinearLayout layout = (LinearLayout) mActivity.findViewById(R.id.linearlayout);
    final ListView lv1 = (ListView) mActivity.findViewById(R.id.listview1);
    final ListView lv2 = (ListView) mActivity.findViewById(R.id.listview2);

    mViewTreeObserver = layout.getViewTreeObserver();
    MockOnGlobalFocusChangeListener listener = new MockOnGlobalFocusChangeListener();
    mViewTreeObserver.addOnGlobalFocusChangeListener(listener);
    assertFalse(listener.hasCalledOnGlobalFocusChanged());
    mInstrumentation.runOnMainSync(
        new Runnable() {
          @Override
          public void run() {
            layout.requestChildFocus(lv1, lv2);
          }
        });
    mInstrumentation.waitForIdleSync();
    assertTrue(listener.hasCalledOnGlobalFocusChanged());

    listener.reset();
    mViewTreeObserver.removeOnGlobalFocusChangeListener(listener);
    assertFalse(listener.hasCalledOnGlobalFocusChanged());
    mInstrumentation.runOnMainSync(
        new Runnable() {
          @Override
          public void run() {
            layout.requestChildFocus(lv1, lv2);
          }
        });
    mInstrumentation.waitForIdleSync();
    assertFalse(listener.hasCalledOnGlobalFocusChanged());
  }
예제 #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bot);
    setupComments();
    setupSpeakButton();
    setupCameraButton();
    setupSendCommentButton();
    setupImageDemoButton();

    surfaceView = (SurfaceView) findViewById(R.id.surfaceView);

    cameraControl = new CameraControl(messageHandler);
    cameraControl.init(getApplicationContext(), surfaceView);
    lastpicture = null;

    dialogManager = new DialogManager(this, this, messageHandler);

    dialogManager.setAttitudeCynic(); // happy

    drawingStartLocation = getIntent().getIntExtra(ARG_DRAWING_START_LOCATION, 0);
    if (savedInstanceState == null) {
      contentRoot
          .getViewTreeObserver()
          .addOnPreDrawListener(
              new ViewTreeObserver.OnPreDrawListener() {
                @Override
                public boolean onPreDraw() {
                  contentRoot.getViewTreeObserver().removeOnPreDrawListener(this);
                  startIntroAnimation();
                  return true;
                }
              });
    }

    tts =
        new TextToSpeech(
            getApplicationContext(),
            new TextToSpeech.OnInitListener() {
              @Override
              public void onInit(int status) {
                if (status != TextToSpeech.ERROR) {
                  tts.setLanguage(Locale.US);
                }
              }
            });

    dialogManager.skypeControl.setTts(tts);

    sr = SpeechRecognizer.createSpeechRecognizer(this);
    sr.setRecognitionListener(new STTListener());

    final AIConfiguration config =
        new AIConfiguration(
            "CLIENT_ACCESS_TOKEN_FAIL",
            "SUBSCRIPTION_KEY_FAIL",
            AIConfiguration.SupportedLanguages.English,
            AIConfiguration.RecognitionEngine.System);
  }
예제 #3
0
  @AfterViews
  void afterViews() {

    toolbar.setTitle(category.getTitle());
    showMenuIcon();
    selectedCategoryInDrawer();

    layout
        .getViewTreeObserver()
        .addOnGlobalLayoutListener(
            new ViewTreeObserver.OnGlobalLayoutListener() {
              @Override
              public void onGlobalLayout() {
                int spanCount =
                    (int)
                        (layout.getWidth()
                            / layout.getResources().getDimension(R.dimen.list_item_width));
                if (spanCount > 1) {
                  layoutManager.setSpanCount(spanCount);
                }
              }
            });

    layoutManager = new GridLayoutManager(getActivity(), 1, LinearLayoutManager.VERTICAL, false);
    recyclerView.setLayoutManager(layoutManager);
    adapter = new ArticlesAdapter(getActivity(), null);
    recyclerView.setAdapter(adapter);

    recyclerView.setOnScrollListener(
        new RecyclerView.OnScrollListener() {
          @Override
          public void onScrolled(RecyclerView recyclerView, int dx, int dy) {

            int visibleItemCount = layoutManager.getChildCount();
            int totalItemCount = layoutManager.getItemCount();
            int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();

            if (!refresh.isRefreshing()
                && (totalItemCount - visibleItemCount) <= firstVisibleItemPosition) {

              loadData(false);
            }
          }
        });

    refresh.setOnRefreshListener(this);
    refresh.setColorSchemeResources(R.color.primary);
    refresh.setProgressViewOffset(
        false,
        0,
        (int)
            TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 24, getResources().getDisplayMetrics()));

    loadData(false);
  }
예제 #4
0
  public void testAddOnGlobalLayoutListener() {
    final LinearLayout layout = (LinearLayout) mActivity.findViewById(R.id.linearlayout);
    mViewTreeObserver = layout.getViewTreeObserver();

    MockOnGlobalLayoutListener listener = new MockOnGlobalLayoutListener();
    assertFalse(listener.hasCalledOnGlobalLayout());
    mViewTreeObserver.addOnGlobalLayoutListener(listener);
    mViewTreeObserver.dispatchOnGlobalLayout();
    assertTrue(listener.hasCalledOnGlobalLayout());
  }
예제 #5
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tutorial_expandir);
    hand = (ImageView) findViewById(R.id.hand);
    num1 = (TextView) findViewById(R.id.view1);
    num2 = (TextView) findViewById(R.id.view2);
    num3 = (TextView) findViewById(R.id.textView3);

    Button siguiente = (Button) findViewById(R.id.btn_siguiente);
    siguiente.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent i = new Intent(TutorialExpandir.this, TutorialSimplificar.class);
            startActivity(i);
          }
        });
    Button anterior = (Button) findViewById(R.id.btn_anterior);
    anterior.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent i = new Intent(TutorialExpandir.this, TutorialCombinar.class);
            startActivity(i);
          }
        });

    final LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
    final ViewTreeObserver vto = layout.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(
        new ViewTreeObserver.OnGlobalLayoutListener() {
          @Override
          public void onGlobalLayout() {
            // Put your code here.
            int[] location = new int[2];
            num3.getLocationOnScreen(location);
            hand.setX(location[0] + num3.getPaddingLeft() / 2 + num3.getWidth() / 2);
            hand.setY(location[1]);

            as = new AnimationSet(true);
            as.setFillAfter(true);
            Animation alpha = new AlphaAnimation(0, 1);
            as.addAnimation(alpha);
            alpha.setStartOffset(100);
            alpha.setDuration(800);
            alpha.setInterpolator(new LinearInterpolator());
            alpha.setAnimationListener(
                new Animation.AnimationListener() {
                  @Override
                  public void onAnimationStart(Animation animation) {
                    num1.setVisibility(View.INVISIBLE);
                    num2.setVisibility(View.INVISIBLE);
                    num3.setVisibility(View.VISIBLE);
                    hand.setImageResource(R.drawable.point);
                    hand.setVisibility(View.VISIBLE);

                    int c = TutorialExpandir.this.getResources().getColor(android.R.color.black);
                    num3.setTextColor(c);
                    num3.setShadowLayer(1, 0, 0, c);
                  }

                  @Override
                  public void onAnimationEnd(Animation animation) {
                    hand.setImageResource(R.drawable.point_hold);
                    int c =
                        TutorialExpandir.this
                            .getResources()
                            .getColor(android.R.color.holo_green_dark);
                    num3.setTextColor(c);
                    num3.setShadowLayer(25, 0, 0, c);
                  }

                  @Override
                  public void onAnimationRepeat(Animation animation) {}
                });

            Animation alpha2 = new AlphaAnimation(1, 0);
            as.addAnimation(alpha2);
            alpha2.setDuration(600);
            alpha2.setInterpolator(new LinearInterpolator());
            alpha2.setStartOffset(500);
            alpha2.setAnimationListener(
                new Animation.AnimationListener() {
                  @Override
                  public void onAnimationStart(Animation animation) {}

                  @Override
                  public void onAnimationEnd(Animation animation) {
                    num1.setVisibility(View.VISIBLE);
                    num2.setVisibility(View.VISIBLE);
                    num3.setVisibility(View.INVISIBLE);
                    Animation expand =
                        AnimationUtils.loadAnimation(TutorialExpandir.this, R.anim.expand_right);
                    expand.setDuration(500);
                    num1.startAnimation(expand);
                    expand =
                        AnimationUtils.loadAnimation(TutorialExpandir.this, R.anim.expand_left);
                    expand.setDuration(500);
                    num2.startAnimation(expand);
                  }

                  @Override
                  public void onAnimationRepeat(Animation animation) {}
                });
            Animation alpha3 = new TranslateAnimation(0, 0, 0, 0);
            as.addAnimation(alpha3);
            alpha3.setDuration(700);
            alpha3.setInterpolator(new LinearInterpolator());
            alpha3.setStartOffset(2000);

            alpha3.setAnimationListener(
                new Animation.AnimationListener() {
                  @Override
                  public void onAnimationStart(Animation animation) {}

                  @Override
                  public void onAnimationEnd(Animation animation) {
                    hand.startAnimation(as);
                  }

                  @Override
                  public void onAnimationRepeat(Animation animation) {}
                });
            hand.startAnimation(as);
            layout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
          }
        });
  }
예제 #6
0
  public void testIsAlive() {
    final LinearLayout layout = (LinearLayout) mActivity.findViewById(R.id.linearlayout);

    mViewTreeObserver = layout.getViewTreeObserver();
    assertTrue(mViewTreeObserver.isAlive());
  }