Exemplo n.º 1
0
    /** Continuously updates Timer's clockText with time elapsed since start. */
    @Override
    public void run() {
      // adds .5 to get more accurate time when casting to int
      timeElapsed = (int) (((System.currentTimeMillis() - startTime) / 1000) + 0.5);
      final int sec = timeElapsed % 60;
      final int min = timeElapsed / 60;
      final int hour = timeElapsed / 3600;
      clockText.post(
          new Runnable() {
            @Override
            public void run() {
              clockText.setText(
                  (hour < 10 ? "0" + hour : hour)
                      + ":"
                      + (min < 10 ? "0" + min : min)
                      + ":"
                      + (sec < 10 ? "0" + sec : sec));
            }
          });

      if (running) {
        // ask current thread to rerun after 100 ms
        handler.postDelayed(this, 100);
      }
    }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {

    if (convertView == null) {
      convertView =
          LayoutInflater.from(getContext()).inflate(R.layout.list_item_review, parent, false);
    }
    final Item item = getItem(position);
    TextView textView = (TextView) convertView.findViewById(R.id.review_item_view);
    int parentWidth = parent.getWidth();
    if (parentWidth != 0) {
      textView.setWidth(parentWidth);
      if (!mListHeightSizingRequested) {
        mListHeightSizingRequested = true;
        textView.post(
            new Runnable() {
              @Override
              public void run() {
                Utility.setListViewHeightBasedOnItems(mListView);
              }
            });
      }
    }
    textView.setText(item.getReviewStr());

    return convertView;
  }
  @Override
  public void onSensorChanged(SensorEvent event) {
    if (mValue == null || event.values.length < 3 || event.values[0] > Integer.MAX_VALUE) {
      return;
    }

    final float x = event.values[0];
    final float y = event.values[1];
    final float z = event.values[2];

    // on some devices in the wild the scalar value does not exist
    final float scalar;
    if (event.values.length >= 4) {
      scalar = event.values[3];
    } else {
      scalar = 0f;
    }
    mValue.post(
        new Runnable() {
          @Override
          public void run() {
            mValue.setText(String.format("x: %.3f\ny: %s\nz: %.3f\nscalar: %.3f", x, y, z, scalar));
          }
        });
  }
Exemplo n.º 4
0
 /// ICallback interface implementation
 public void call(final String iData) {
   _logTextView.post(
       new Runnable() {
         public void run() {
           updateLog(iData);
           updateStatus();
         }
       });
 }
Exemplo n.º 5
0
  /*
     Este método sirve para actualizar el texto que aparece en pantalla
     y que refleja el número de segundos restantes que le quedan al cronómetro

     Hay que invocarlo pasandole como primer argumento la variable txtTiempoRestante
  */
  public void actualizarTiempo(final TextView txt, final double tiempoRestante) {
    txt.post(
        new Runnable() {
          @Override
          public void run() {
            txt.setText(String.format("%.1f", tiempoRestante) + " s.");
          }
        });
  }
Exemplo n.º 6
0
 private void refrescarCancionSonando() {
   text_playing.post(
       new Runnable() {
         public void run() {
           text_playing.setText(cancion_sonando.getNombreCancion());
           text_autorPlaying.setText(cancion_sonando.getNombreAutor());
         }
       });
 }
 private void setDialogTextView(final String newString) {
   computeTextView.post(
       new Runnable() {
         @Override
         public void run() {
           computeTextView.setText(newString);
         }
       });
 }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

      if (convertView == null) {
        convertView = LayoutInflater.from(getActivity()).inflate(R.layout.review_card, null);
      }

      ReviewData reviewData = getItem(position);

      // Author name
      TextView authorTextView = (TextView) convertView.findViewById(R.id.review_author);
      authorTextView.setText(reviewData.getAuthor());

      // Review content
      final TextView reviewContentTextView =
          (TextView) convertView.findViewById(R.id.review_content);
      reviewContentTextView.setText(reviewData.getContent());

      // Read more text
      final TextView readMoreTextView = (TextView) convertView.findViewById(R.id.read_more_action);

      // TextView.getLineCount() will return 0 after setText(), have to check getLineCount() in
      // TextView.post(Runnable)
      reviewContentTextView.post(
          new Runnable() {
            @Override
            public void run() {
              // If the review content is longer than a number of lines, show read-more TextView
              if (reviewContentTextView.getLineCount()
                  > getResources().getInteger(R.integer.review_default_line_num)) {
                readMoreTextView.setOnClickListener(
                    new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {

                        // Scroll down animation of review
                        ObjectAnimator animation =
                            ObjectAnimator.ofInt(
                                reviewContentTextView,
                                "maxLines",
                                reviewContentTextView.getLineCount());
                        animation.setDuration(1000).start();
                        readMoreTextView.setVisibility(View.GONE);
                      }
                    });
              } else { // If the review content short enough, read-more feature is no needed, hide
                // it
                readMoreTextView.setVisibility(View.GONE);
              }
            }
          });

      return convertView;
    }
 protected void executeImpl() throws TestFrameworkException {
   final TextView textView = getSpecialistView();
   if (textView == null) return;
   textView.post(
       new Runnable() {
         @Override
         public void run() {
           textView.setText(Text);
         }
       });
   sendSuccessResult();
 }
Exemplo n.º 10
0
 /**
  * Gets the information for the currently playing song.
  *
  * @throws IOException If we cannot connect.
  */
 public void getInfo() throws IOException {
   Socket clientSocket = new Socket(PlayerControl.GUMSTIX_IP, PlayerControl.RECEIVE_SOCKET_PORT);
   BufferedReader dataInputStream =
       new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
   final String title = dataInputStream.readLine();
   final String artistName = dataInputStream.readLine();
   clientSocket.close();
   songTitle.post(
       new Runnable() {
         @Override
         public void run() {
           String setTitle = title.trim();
           songTitle.setText(setTitle.isEmpty() ? "No Title" : setTitle);
         }
       });
   artist.post(
       new Runnable() {
         @Override
         public void run() {
           String setArtist = artistName.trim();
           artist.setText(artistName.isEmpty() ? "No Artist" : setArtist);
         }
       });
 }
Exemplo n.º 11
0
  void toc(final String info) {
    final float time = (System.nanoTime() - start) / 1000000000.0f;

    tv.post(
        new Runnable() {

          @Override
          public void run() {
            StringBuilder buff = new StringBuilder(tv.getText());
            buff.append(info).append(", ").append(time).append(" secs\n");
            tv.setText(buff.toString());
          }
        });

    Log.d("MicroBenchmarks", info + ", " + time);
  }
  @Override
  public void onSensorChanged(SensorEvent event) {
    if (mValue == null || event.values[0] > Integer.MAX_VALUE) {
      return;
    }

    final float x = event.values[0];
    final float y = event.values[1];
    final float z = event.values[2];
    mValue.post(
        new Runnable() {
          @Override
          public void run() {
            mValue.setText(String.format("x: %s\ny: %s\nz: %s", x, y, z));
          }
        });
  }
Exemplo n.º 13
0
  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Es para quitar los botones de compartir y favorito, para que no se vean en la interfaz
    ImageButton btn = (ImageButton) findViewById(R.id.btnFav);
    btn.setImageDrawable(null);
    btn.setEnabled(false);
    ImageButton btn1 = (ImageButton) findViewById(R.id.btnshare);
    btn1.setImageDrawable(null);
    btn1.setEnabled(false);
    //////////////////////////////////////////////////////////////////////////////////////
    listadoAdapter = new AdaptadorLista(this, lista, R.layout.rowstyle);
    setListAdapter(listadoAdapter);
    text_playing = (TextView) findViewById(R.id.txtPlaying);
    text_playing.setSelected(true);
    text_autorPlaying = (TextView) findViewById(R.id.txtPlayingAutor);
    conex = new ConnectionManager();
    conex.conexion.addServerMessageListener(this);
    if (cancion_sonando == null) {
      cancion_sonando = new Cancion("Nombre canción", "Artista", "Album", 0, 0, false, false);
      text_playing.post(
          new Runnable() {
            public void run() {
              try {
                conex.conexion.enviarMensaje("0|0");
              } catch (Exception ex) {
              }
            }
          });
    }
    refrescarCancionSonando();
    p = this;
  }
  public void onClick(View v) {
    int id = v.getId();
    if (id >= idLVFirstItem) {
      int nLVIndexClick = id - idLVFirstItem;
      Log.d(LT, "LV Item Click:" + nLVIndexClick);
      for (InputDevice idev : events.m_Devs) {
        if (idev.getId() == nLVIndexClick) {
          if (idev.Open(true)) {
            // refresh listview
            PopulateListView();
            // inform user
            Toast.makeText(this, "Device opened successfully!", Toast.LENGTH_SHORT).show();
          } else {
            Toast.makeText(this, "Device failed to open. Do you have root?", Toast.LENGTH_SHORT)
                .show();
          }
          break;
        }
      }
    }

    switch (id) {
      case idButScan:
        {
          Log.d(LT, "Scanning for input dev files.");
          // init event node files
          int res = events.Init();
          // debug results
          Log.d(LT, "Event files:" + res);
          // try opening all
          PopulateListView();
        }
      case idButInjectKey:
        if (m_selectedDev != -1) {
          // see input.h in Android NDK, sequence represents the codes for pocketmagic.net
          final int keys[] = new int[] {25, 24, 46, 37, 18, 20, 50, 30, 34, 23, 46, 52, 49, 18, 20};
          // send all these keys with half a second delay
          Thread sender =
              new Thread(
                  new Runnable() {
                    public void run() {
                      for (int i = 0; i < keys.length; i++) {
                        Log.d(
                            LT,
                            "Sending:"
                                + keys[i]
                                + " to:"
                                + events.m_Devs.get(m_selectedDev).getName());
                        events.m_Devs.get(m_selectedDev).SendKey(keys[i], true); // key down
                        events.m_Devs.get(m_selectedDev).SendKey(keys[i], false); // key up
                        // a short delay before next character, just for testing purposes
                        try {
                          Thread.sleep(1000);
                        } catch (InterruptedException e) {
                          e.printStackTrace();
                        }
                      }
                    }
                  });
          sender.start();
        } else
          Toast.makeText(
                  this,
                  "Select a valid device first, using the spinner to the left.",
                  Toast.LENGTH_SHORT)
              .show();
        break;

      case idButInjectTouch:
        // absolute coordinates, on my device they go up to 570x960
        if (m_selectedDev != -1) events.m_Devs.get(m_selectedDev).SendTouchDownAbs(155, 183);
        else
          Toast.makeText(
                  this,
                  "Select a valid device first, using the spinner to the left.",
                  Toast.LENGTH_SHORT)
              .show();
        break;

      case idButTest:
        Thread sender =
            new Thread(
                new Runnable() {
                  public void run() {
                    for (int i = 0; i < 5; i++) {
                      SendHomeKeyToKeypad();
                      // a short delay before next character, just for testing purposes
                      try {
                        Thread.sleep(2000);
                      } catch (InterruptedException e) {
                        e.printStackTrace();
                      }
                    }
                  }
                });
        sender.start();

        break;
      case idButMonitorStart:
        if (m_bMonitorOn)
          Toast.makeText(
                  this,
                  "Event monitor already working. Consider opening more devices to monitor.",
                  Toast.LENGTH_SHORT)
              .show();
        else {
          m_tvMonitor.post(
              new Runnable() {

                public void run() {
                  m_tvMonitor.setText("Event Monitor running, waiting for data.");
                }
              });
          StartEventMonitor();
        }
        break;
      case idButMonitorStop:
        Toast.makeText(this, "Event monitor stopped.", Toast.LENGTH_SHORT).show();

        StopEventMonitor();
        m_tvMonitor.post(
            new Runnable() {

              public void run() {
                m_tvMonitor.setText("Event Monitor stopped.");
              }
            });
        break;
    }
  }
  @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
  @Override
  public View onCreateView(
      LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    mRoot = inflater.inflate(R.layout.fragment_moviedetail, container, false);
    if (VersionUtils.isJellyBean() && container != null) {
      mRoot.setMinimumHeight(container.getMinimumHeight());
    }
    ButterKnife.inject(this, mRoot);

    if (!VersionUtils.isJellyBean()) {
      mPlayButton.setBackgroundDrawable(
          PixelUtils.changeDrawableColor(
              mPlayButton.getContext(), R.drawable.play_button_circle, sMovie.color));
    } else {
      mPlayButton.setBackground(
          PixelUtils.changeDrawableColor(
              mPlayButton.getContext(), R.drawable.play_button_circle, sMovie.color));
    }

    mTitle.setText(sMovie.title);
    if (!sMovie.rating.equals("-1")) {
      Double rating = Double.parseDouble(sMovie.rating);
      mRating.setProgress(rating.intValue());
      mRating.setVisibility(View.VISIBLE);
    } else {
      mRating.setVisibility(View.GONE);
    }

    String metaDataStr = sMovie.year;
    if (!TextUtils.isEmpty(sMovie.runtime)) {
      metaDataStr += " • ";
      metaDataStr += sMovie.runtime + " " + getString(R.string.minutes);
    }

    if (!TextUtils.isEmpty(sMovie.genre)) {
      metaDataStr += " • ";
      metaDataStr += sMovie.genre;
    }

    mMeta.setText(metaDataStr);

    if (!TextUtils.isEmpty(sMovie.synopsis)) {
      mSynopsis.setText(sMovie.synopsis);
      mSynopsis.post(
          new Runnable() {
            @Override
            public void run() {
              boolean ellipsized = false;
              Layout layout = mSynopsis.getLayout();
              if (layout == null) return;
              int lines = layout.getLineCount();
              if (lines > 0) {
                int ellipsisCount = layout.getEllipsisCount(lines - 1);
                if (ellipsisCount > 0) {
                  ellipsized = true;
                }
              }
              mReadMore.setVisibility(ellipsized ? View.VISIBLE : View.GONE);
            }
          });
    } else {
      mSynopsis.setClickable(false);
      mReadMore.setVisibility(View.GONE);
    }

    mWatchTrailer.setVisibility(
        sMovie.trailer == null || sMovie.trailer.isEmpty() ? View.GONE : View.VISIBLE);

    mSubtitles.setFragmentManager(getFragmentManager());
    mQuality.setFragmentManager(getFragmentManager());
    mSubtitles.setTitle(R.string.subtitles);
    mQuality.setTitle(R.string.quality);

    mSubtitles.setText(R.string.loading_subs);
    mSubtitles.setClickable(false);

    if (sMovie.getSubsProvider() != null) {
      sMovie
          .getSubsProvider()
          .getList(
              sMovie,
              new SubsProvider.Callback() {
                @Override
                public void onSuccess(Map<String, String> subtitles) {
                  if (!mAttached) return;

                  if (subtitles == null) {
                    ThreadUtils.runOnUiThread(
                        new Runnable() {
                          @Override
                          public void run() {
                            mSubtitles.setText(R.string.no_subs_available);
                          }
                        });
                    return;
                  }

                  sMovie.subtitles = subtitles;

                  String[] languages = subtitles.keySet().toArray(new String[subtitles.size()]);
                  Arrays.sort(languages);
                  final String[] adapterLanguages = new String[languages.length + 1];
                  adapterLanguages[0] = "no-subs";
                  System.arraycopy(languages, 0, adapterLanguages, 1, languages.length);

                  String[] readableNames = new String[adapterLanguages.length];
                  for (int i = 0; i < readableNames.length; i++) {
                    String language = adapterLanguages[i];
                    if (language.equals("no-subs")) {
                      readableNames[i] = getString(R.string.no_subs);
                    } else {
                      Locale locale = LocaleUtils.toLocale(language);
                      readableNames[i] = locale.getDisplayName(locale);
                    }
                  }

                  mSubtitles.setListener(
                      new OptionSelector.SelectorListener() {
                        @Override
                        public void onSelectionChanged(int position, String value) {
                          onSubtitleLanguageSelected(adapterLanguages[position]);
                        }
                      });
                  mSubtitles.setData(readableNames);
                  ThreadUtils.runOnUiThread(
                      new Runnable() {
                        @Override
                        public void run() {
                          mSubtitles.setClickable(true);
                        }
                      });

                  String defaultSubtitle =
                      PrefUtils.get(mSubtitles.getContext(), Prefs.SUBTITLE_DEFAULT, null);
                  if (subtitles.containsKey(defaultSubtitle)) {
                    onSubtitleLanguageSelected(defaultSubtitle);
                    mSubtitles.setDefault(Arrays.asList(adapterLanguages).indexOf(defaultSubtitle));
                  } else {
                    onSubtitleLanguageSelected("no-subs");
                    mSubtitles.setDefault(Arrays.asList(adapterLanguages).indexOf("no-subs"));
                  }
                }

                @Override
                public void onFailure(Exception e) {
                  mSubtitles.setData(new String[0]);
                  mSubtitles.setClickable(true);
                }
              });
    } else {
      mSubtitles.setClickable(false);
      mSubtitles.setText(R.string.no_subs_available);
    }

    if (sMovie.torrents.size() > 0) {
      final String[] qualities =
          sMovie.torrents.keySet().toArray(new String[sMovie.torrents.size()]);
      SortUtils.sortQualities(qualities);
      mQuality.setData(qualities);
      mQuality.setListener(
          new OptionSelector.SelectorListener() {
            @Override
            public void onSelectionChanged(int position, String value) {
              mSelectedQuality = value;
              renderHealth();
              updateMagnet();
            }
          });
      String defaultQuality = PrefUtils.get(mQuality.getContext(), Prefs.QUALITY_DEFAULT, "720p");
      int qualityIndex =
          Arrays.asList(qualities).contains(defaultQuality)
              ? Arrays.asList(qualities).indexOf(defaultQuality)
              : qualities.length - 1;
      mSelectedQuality = qualities[qualityIndex];
      mQuality.setText(mSelectedQuality);
      mQuality.setDefault(qualityIndex);
      renderHealth();
      updateMagnet();
    }

    if (mCoverImage != null) {
      Picasso.with(mCoverImage.getContext()).load(sMovie.image).into(mCoverImage);
    }

    return mRoot;
  }
Exemplo n.º 16
0
 public void displayMessage(String text) {
   tv.post(new MessagePoster(text));
 }
Exemplo n.º 17
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    sipUri = getArguments().getString("SipUri");
    String displayName = getArguments().getString("DisplayName");
    String pictureUri = getArguments().getString("PictureUri");

    view = inflater.inflate(R.layout.chat, container, false);

    useLinphoneMessageStorage = getResources().getBoolean(R.bool.use_linphone_chat_storage);

    contactName = (TextView) view.findViewById(R.id.contactName);
    contactPicture = (AvatarWithShadow) view.findViewById(R.id.contactPicture);

    sendMessage = (TextView) view.findViewById(R.id.sendMessage);
    sendMessage.setOnClickListener(this);

    remoteComposing = (TextView) view.findViewById(R.id.remoteComposing);
    remoteComposing.setVisibility(View.GONE);

    messagesList = (ListView) view.findViewById(R.id.chatMessageList);

    message = (EditText) view.findViewById(R.id.message);
    if (!getActivity().getResources().getBoolean(R.bool.allow_chat_multiline)) {
      message.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE);
      message.setMaxLines(1);
    }

    uploadLayout = (RelativeLayout) view.findViewById(R.id.uploadLayout);
    uploadLayout.setVisibility(View.GONE);
    textLayout = (RelativeLayout) view.findViewById(R.id.messageLayout);

    progressBar = (ProgressBar) view.findViewById(R.id.progressbar);
    sendImage = (TextView) view.findViewById(R.id.sendPicture);
    if (!getResources().getBoolean(R.bool.disable_chat_send_file)) {
      registerForContextMenu(sendImage);
      sendImage.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              pickImage();
            }
          });
    } else {
      sendImage.setEnabled(false);
    }

    cancelUpload = (ImageView) view.findViewById(R.id.cancelUpload);
    cancelUpload.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            uploadThread.interrupt();
            uploadLayout.setVisibility(View.GONE);
            textLayout.setVisibility(View.VISIBLE);
            progressBar.setProgress(0);
          }
        });

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    if (lc != null) {
      chatRoom = lc.getOrCreateChatRoom(sipUri);
      // Only works if using liblinphone storage
      chatRoom.markAsRead();
    }

    displayChatHeader(displayName, pictureUri);

    uploadServerUri = LinphonePreferences.instance().getSharingPictureServerUrl();

    textWatcher =
        new TextWatcher() {
          public void afterTextChanged(Editable arg0) {}

          public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {}

          public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            if (message.getText().toString().equals("")) {
              sendMessage.setEnabled(false);
            } else {
              if (chatRoom != null) chatRoom.compose();
              sendMessage.setEnabled(true);
            }
          }
        };

    // Force hide keyboard
    if (LinphoneActivity.isInstanciated()) {
      InputMethodManager imm =
          (InputMethodManager)
              LinphoneActivity.instance().getSystemService(Context.INPUT_METHOD_SERVICE);
      imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }

    // Workaround for SGS3 issue
    if (savedInstanceState != null) {
      fileToUploadPath = savedInstanceState.getString("fileToUploadPath");
      imageToUpload = savedInstanceState.getParcelable("imageToUpload");
    }
    if (fileToUploadPath != null || imageToUpload != null) {
      sendImage.post(
          new Runnable() {
            @Override
            public void run() {
              sendImage.showContextMenu();
            }
          });
    }

    return view;
  }