@Override
  public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.sortname) {
      list.post(
          new Runnable() {
            @Override
            public void run() {
              sortdateMenuItem.setVisible(true);
              sortnameMenuItem.setVisible(false);
            }
          });
      removeBack();
      Collections.sort(items, new FileNameOrderComparator());
      insertBack();
      adapter.notifyDataSetChanged();
      return true;
    } else if (id == R.id.sortdate) {
      list.post(
          new Runnable() {
            @Override
            public void run() {
              sortdateMenuItem.setVisible(false);
              sortnameMenuItem.setVisible(true);
            }
          });
      removeBack();
      Collections.sort(items, new FileDateOrderComparator());
      insertBack();
      adapter.notifyDataSetChanged();
      return true;
    } else if (id == R.id.search) {
      Bundle bundle = new Bundle();
      bundle.putString("root", path);
      SearchFileFragment searchFragment = new SearchFileFragment();
      searchFragment.setArguments(bundle);
      pickerActivity
          .getFragmentManager()
          .beginTransaction()
          // .setCustomAnimations(R.animator.picker_fragment_explorer_welcome_enter,
          // R.animator.picker_fragment_explorer_welcome_exit)
          .replace(R.id.container, searchFragment)
          .addToBackStack("search")
          .commit();
      // pickerActivity.searchDisable();

      return true;
    }
    return super.onOptionsItemSelected(item);
  }
Ejemplo n.º 2
0
 public void displayGoals(boolean display_present) {
   this.display_present = display_present;
   MySQLiteHelper db = new MySQLiteHelper(activity);
   List<Goal> goals = db.getAllGoals();
   goalsToDisplay.clear();
   for (Goal goal : goals) {
     if (goal.getComplete() == Goal.INCOMPLETE && display_present) {
       goalsToDisplay.add(goal);
     } else if (goal.getComplete() == Goal.COMPLETE && !display_present) {
       goalsToDisplay.add(goal);
     }
   }
   if (goalAdapter == null) {
     goalAdapter = new GoalAdapter(activity, R.layout.goal_listview_row, goalsToDisplay);
   } else {
     goalsListView.post(
         new Runnable() {
           @Override
           public void run() {
             goalAdapter.notifyDataSetChanged();
           }
         });
   }
   if (goals.size() == 0 && display_present) {
     txtviewIntro.setText("Press the action button to add a goal.");
     txtviewIntro.setVisibility(View.VISIBLE);
   } else if (!display_present && Goal.getCompleteGoals(goals).size() == 0) {
     txtviewIntro.setText("When you complete a goal it will be displayed here.");
     txtviewIntro.setVisibility(View.VISIBLE);
   } else {
     txtviewIntro.setVisibility(View.GONE);
   }
 }
Ejemplo n.º 3
0
  private void tryIP(final String ip, final String location, int timeout) throws IOException {
    final String description = Networker.doNetwork(location, "GET", "", timeout).getBody();

    // Parsing with RegEx allowed here because the output format is fairly strict
    final String modelName = Util.quickMatch("<modelName>(.*?)</modelName>", description);

    // Check from description if we're dealing with a hue bridge or some other device
    if (modelName.toLowerCase().contains("philips hue bridge")) {
      try {
        final boolean access =
            HueService.userExists(ip, Util.getDeviceIdentifier(LinkActivity.this));
        final String name =
            Util.quickMatch("<friendlyName>(.*?) \\([0-9.]+\\)</friendlyName>", description);
        final String mac = Util.quickMatch("<serialNumber>(.*?)</serialNumber>", description);

        bridgesList.post(
            new Runnable() {
              @Override
              public void run() {
                Bridge b = new Bridge(ip, mac, name, access);
                bridges.add(b);
                bridgesAdapter.add(b);
              }
            });
      } catch (Exception e) {
        // Do nothing, this basically serves as an extra check to see if it's really a hue bridge
        Log.w("hue2", "Found device that identifies as Hue bridge, but isn't one? (" + ip + ")");
        e.printStackTrace();
      }
    }
  }
  /** Populated the listview with discovered devices, and the spinner with those that are open */
  private void PopulateListView() {
    m_lvDevices.post(
        new Runnable() {
          public void run() {
            m_lvDevices.setAdapter(null);
            ArrayList<ListViewItem> m_Devices = new ArrayList<ListViewItem>();
            for (InputDevice idev : events.m_Devs) {
              ListViewItem device =
                  new ListViewItem(
                      idev.getName(), idev.getPath(), idev.getOpen(), idLVFirstItem + idev.getId());
              m_Devices.add(device);
            }
            CustomAdapter m_lvAdapter = new CustomAdapter(MainActivity.this, m_Devices);
            if (m_lvDevices != null) m_lvDevices.setAdapter(m_lvAdapter);
          }
        });
    m_selDevSpinner.post(
        new Runnable() {
          public void run() {
            ArrayList<String> openDevs = new ArrayList<String>();

            for (InputDevice idev : events.m_Devs) {
              if (idev.getOpen()) openDevs.add(idev.getName());
            }
            // populate spinner
            ArrayAdapter<String> adapter =
                new ArrayAdapter<String>(
                    MainActivity.this, android.R.layout.simple_spinner_item, openDevs);
            adapter.setDropDownViewResource(android.R.layout.select_dialog_singlechoice);
            // changes spin size and popup box size/color
            m_selDevSpinner.setAdapter(adapter);
          }
        });
  }
Ejemplo n.º 5
0
 public void addFilter(final Filter<? super Tables.Tracks> filter, boolean permanant) {
   (permanant ? permanentFilters : filters).add(filter);
   filterList.post(
       new Runnable() {
         public void run() {
           filterListAdapter.add(filter);
         }
       });
 }
  private void Autoscroll(final ListView listView) {
    // this list is autoscrolled by using this method
    // What is happening in this method is that  we are creating a new runnable thread
    // and in this thread after every 20 milli-seconds
    // we are scrolling the list by 1 pixel

    // To use this method, we needed a reference to the listView itself, which we pass as argument
    // We could have easily got that reference in the MainActivty, where we initialise the list
    // but we wanted to put all the code in the adapter so that's why we did it here

    // So to get the reference what we did was that
    // In the adapter's getView method, the third argument is " ViewGroup parent"
    // Since the parent, here is listView, we couild call the method Autoscroll(parent)
    // but it expects a Listview object. Now we know that ViewGroup class is a super class
    // of all views in android so, we cast it -->  (ListView)parent
    // So now we can call this method

    // But there is a problem, if we call this method in the getView method.
    // The thing is that getView method is called for every child view of list
    // that means, a new thread will be created for every child view
    // Since we have 2500 child views, so 2500 new threads will be created and
    // they will all scroll the listview

    // So to tackle this problem , we create a boolean variable called "newAutoScroll"
    // we initialise it to true, once in the constructor
    // and call the Autoscroll method if it is tue.
    // Once the method, is called, we make it false.
    // so that for next call to getView, newAutoScroll would be false
    // and autoscroll will not be called again.. never

    final long totalScrollTime =
        Long
            .MAX_VALUE; // total scroll time. I think that 300 000 000 years is close enouth to
                        // infinity. if not enought you can restart timer in onFinish()

    final int scrollPeriod = 20; // every 20 ms scoll will happened. smaller values for smoother

    final int heightToScroll =
        1; // will be scrolled to 20 px every time. smaller values for smoother scrolling

    listView.post(
        new Runnable() {
          @Override
          public void run() {
            new CountDownTimer(totalScrollTime, scrollPeriod) {
              public void onTick(long millisUntilFinished) {
                listView.scrollListBy(heightToScroll);
              }

              public void onFinish() {
                // you can add code for restarting timer here
              }
            }.start();
          }
        });
  }
 // SCROLL TO BOTTOM
 private void scrollMyListViewToBottom() {
   lvMessages.post(
       new Runnable() {
         @Override
         public void run() {
           lvMessages.setSelection(lvMessages.getCount() - 1);
           lvMessages.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
         }
       });
 }
  public void scrollToTop() {
    mListView.post(
        new Runnable() {

          @Override
          public void run() {
            if (mListView.getFirstVisiblePosition() > 10) {
              mListView.setSelection(10);
            }
            mListView.smoothScrollToPosition(0);
          }
        });
  }
Ejemplo n.º 9
0
  private void stopSearching() {
    if (bridgeSearchTask != null) {
      bridgeSearchTask.cancel(true);
      bridgeSearchTask = null;

      bridgesList.post(
          new Runnable() {
            @Override
            public void run() {
              setSearchIndicator(false);
            }
          });
    }
  }
 private void resumeUserScrollPosition() {
   // Restore the scroll position and offset of the top list item
   // From: http://stackoverflow.com/a/3035521
   final Intent intent = getIntent();
   if (intent.hasExtra(TOP_LIST_ITEM)) {
     audioFileView.post(
         new Runnable() {
           @Override
           public void run() {
             int index = intent.getIntExtra(TOP_LIST_ITEM, 0);
             int offset = intent.getIntExtra(TOP_LIST_ITEM_OFFSET, 0);
             audioFileView.setSelectionFromTop(index, offset);
           }
         });
   }
 }
Ejemplo n.º 11
0
 @Override
 public void onActionModeFinished(ActionMode mode) {
   super.onActionModeFinished(mode);
   if (inviteIntent) {
     finish();
   } else {
     this.isActionMode = false;
     contactsView.clearChoices();
     contactsView.requestLayout();
     contactsView.post(
         new Runnable() {
           @Override
           public void run() {
             contactsView.setChoiceMode(ListView.CHOICE_MODE_NONE);
           }
         });
     search.setEnabled(true);
   }
 }
Ejemplo n.º 12
0
  /**
   * scroll to the first hot line, if possible (that is, first unread line in a private buffer * or
   * the first unread highlight) * can be called multiple times, will only run once * posts to the
   * listview to make sure it's fully completed loading the items * after setting the adapter or
   * updating lines
   */
  public void scrollToHotLineIfNeeded() {
    if (DEBUG_AUTOSCROLLING) logger.debug("scrollToHotLineIfNeeded()");
    if (buffer != null
        && buffer.isWatched
        && buffer.holdsAllLines
        && (highlights > 0 || privates > 0)) {
      uiLines.post(
          new Runnable() {
            @Override
            public void run() {
              int count = linesAdapter.getCount(), idx = -2;

              if (privates > 0) {
                int p = 0;
                for (idx = count - 1; idx >= 0; idx--) {
                  Line line = (Line) linesAdapter.getItem(idx);
                  if (line.type == Line.LINE_MESSAGE && ++p == privates) break;
                }
              } else if (highlights > 0) {
                int h = 0;
                for (idx = count - 1; idx >= 0; idx--) {
                  Line line = (Line) linesAdapter.getItem(idx);
                  if (line.highlighted && ++h == highlights) break;
                }
              }

              if (idx == -1)
                Toast.makeText(
                        getActivity(),
                        activity.getString(R.string.autoscroll_no_line),
                        Toast.LENGTH_SHORT)
                    .show();
              else if (idx > 0) uiLines.smoothScrollToPosition(idx);

              highlights = privates = 0;
            }
          });
    }
  }
Ejemplo n.º 13
0
  // TODO 设置listview下拉刷新,为了阅后即焚暂时取消
  private void setupWidget() {
    singleChatLv.setOnScrollListener(mOnScrollListener);
    singleChatLv.setTranscriptMode(AbsListView.TRANSCRIPT_MODE_NORMAL);
    singleChatLv.setOnTouchListener(mOnTouchListener);
    singleChatLv.setOnItemClickListener(mItemClickListener);
    singleChatLv.setKeepScreenOn(true);
    singleChatLv.post(
        new Runnable() {
          @Override
          public void run() {
            singleChatLv.setSelection(singleChatLv.getCount());
          }
        });
    registerForContextMenu(singleChatLv);

    mmPullDownView = (ChatPullDownListView) findViewById(R.id.chat_list_pulldown_view);
    mmPullDownView.setTopViewInitialize(true);
    mmPullDownView.setIsCloseTopAllowRefersh(false);
    mmPullDownView.setHasbottomViewWithoutscroll(false);
    mmPullDownView.setOnRefreshAdapterDataListener(mOnRefreshAdapterDataListener);
    mmPullDownView.setOnListViewTopListener(mOnListViewTopListener);
    mmPullDownView.setOnListViewBottomListener(mOnListViewBottomListener);
  }
Ejemplo n.º 14
0
  /**
   * 切换时保持可见headerView的位置不动
   *
   * @param listView
   * @return
   */
  public boolean restoreListView(final ListView listView) {
    final int lastIndex = 1 - mIndex;
    mScrollValue = -mScrollY[lastIndex];
    if (mScrollValue >= 0) {
      int firstVisiablePosition = listView.getFirstVisiblePosition();
      if (firstVisiablePosition > 0 && mScrollValue >= mMaxScrollHeight) {
        mScrollY[lastIndex] = 1;
        return true;
      }

      listView.post(
          new Runnable() {

            @Override
            public void run() {
              listView.setSelectionFromTop(0, -mScrollValue);
            }
          });
      mScrollY[lastIndex] = 1;
      return true;
    }
    return false;
  }
Ejemplo n.º 15
0
 public boolean back() {
   Mode backMode;
   switch (currMode) {
     case Album:
       backMode = Mode.Artist;
       break;
     case Artist:
       backMode = Mode.Genre;
       break;
     case Genre:
       backMode = null;
       break;
     case Track:
       backMode = Mode.Album;
       break;
     case Dir:
       backMode = Mode.Dir;
       break;
     default:
       throw new RuntimeException(currMode.name() + " not expexted here");
   }
   final List<Filter<? super Tables.Tracks>> filtersAddedByBack = filtersAddWithMode.get(backMode);
   if (backMode == null || filtersAddedByBack.isEmpty()) {
     return true;
   } else {
     final Filter<? super Tables.Tracks> filterAddedByBack =
         filtersAddedByBack.remove(filtersAddedByBack.size() - 1);
     filterList.post(
         new Runnable() {
           public void run() {
             removeFilter(filterAddedByBack);
           }
         });
     change(backMode, null, false);
     return false;
   }
 }
Ejemplo n.º 16
0
  private void updateLookAdapter(String name, String fileName) {
    name = Utils.getUniqueLookName(name);

    LookData lookData = new LookData();
    lookData.setLookFilename(fileName);
    lookData.setLookName(name);
    lookDataList.add(lookData);

    adapter.notifyDataSetChanged();

    if (lookDataListChangedAfterNewListener != null) {
      lookDataListChangedAfterNewListener.onLookDataListChangedAfterNew(lookData);
    }

    // scroll down the list to the new item:
    final ListView listView = getListView();
    listView.post(
        new Runnable() {
          @Override
          public void run() {
            listView.setSelection(listView.getCount() - 1);
          }
        });
  }
  @Override
  public Animator onCreateAnimator(int transit, boolean enter, int nextAnim) {
    Log.d("Explorer animation", "CreateAnimator: " + transit + " " + enter + " " + nextAnim);

    int animationLength = 0;

    if (nextAnim == R.animator.picker_fragment_explorer_welcome_enter) {
      list.setAlpha(0);
      list.post(
          new Runnable() {
            @Override
            public void run() {
              list.setAlpha(1);
              int offsetIncreaseOffset = 0;
              for (int i = 0; i < list.getChildCount(); i++) {
                View searchItemView = list.getChildAt(i);
                AnimationSet slideInAnimation = new AnimationSet(true);
                slideInAnimation.setInterpolator(new MaterialInterpolator());
                slideInAnimation.setDuration(180);
                if (items.get(i) instanceof HeaderItem) {
                  offsetIncreaseOffset += 150;
                  slideInAnimation.setStartOffset(i * 50 + offsetIncreaseOffset);
                  offsetIncreaseOffset += 200;
                } else slideInAnimation.setStartOffset(i * 50 + offsetIncreaseOffset);
                AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);
                slideInAnimation.addAnimation(alphaAnimation);
                TranslateAnimation translateAnimation = new TranslateAnimation(0, 0, 150, 0);
                slideInAnimation.addAnimation(translateAnimation);
                searchItemView.startAnimation(slideInAnimation);
              }
            }
          });
      animationLength = list.getChildCount() * 100 + 50;
      Log.d("Explorer animation", "CreateAnimator: enter");
    } else if (nextAnim == R.animator.picker_fragment_explorer_enter) {
      list.setAlpha(0);
      list.post(
          new Runnable() {
            @Override
            public void run() {
              list.setAlpha(1);
              int offsetIncreaseOffset = 0;
              for (int i = 0; i < list.getChildCount(); i++) {
                View searchItemView = list.getChildAt(i);
                AnimationSet slideInAnimation = new AnimationSet(true);
                slideInAnimation.setInterpolator(new MaterialInterpolator());
                slideInAnimation.setDuration(100);
                slideInAnimation.setStartOffset(i * 50 + offsetIncreaseOffset);
                AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);
                slideInAnimation.addAnimation(alphaAnimation);
                TranslateAnimation translateAnimation = new TranslateAnimation(100, 0, 0, 0);
                slideInAnimation.addAnimation(translateAnimation);
                searchItemView.startAnimation(slideInAnimation);
              }
            }
          });
      animationLength = list.getChildCount() * 100 + 50;
      Log.d("Explorer animation", "CreateAnimator: enter");
    } else if (nextAnim == R.animator.picker_fragment_explorer_welcome_exit
        || nextAnim == R.animator.picker_fragment_explorer_exit) {
      for (int i = 0; i < list.getChildCount(); i++) {
        View searchItemView = list.getChildAt(i);
        AnimationSet slideInAnimation = new AnimationSet(true);
        slideInAnimation.setInterpolator(new MaterialInterpolator());
        slideInAnimation.setDuration(100);
        slideInAnimation.setStartOffset(i * 50);
        slideInAnimation.setFillAfter(true);
        AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
        alphaAnimation.setFillAfter(true);
        slideInAnimation.addAnimation(alphaAnimation);
        TranslateAnimation translateAnimation = new TranslateAnimation(0, -100, 0, 0);
        slideInAnimation.addAnimation(translateAnimation);
        searchItemView.startAnimation(slideInAnimation);
      }

      animationLength = 0; // list.getChildCount() * 100 + 50;
      Log.d("Explorer animation", "CreateAnimator: exit");
    } else if (nextAnim == R.animator.picker_fragment_explorer_return) {
      list.setAlpha(0);
      list.post(
          new Runnable() {
            @Override
            public void run() {
              list.setAlpha(1);
              for (int i = 0; i < list.getChildCount(); i++) {
                View searchItemView = list.getChildAt(i);
                AnimationSet slideInAnimation = new AnimationSet(true);
                slideInAnimation.setInterpolator(new MaterialInterpolator());
                slideInAnimation.setDuration(100);
                slideInAnimation.setStartOffset(i * 50);
                AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);
                slideInAnimation.addAnimation(alphaAnimation);
                TranslateAnimation translateAnimation = new TranslateAnimation(-100, 0, 0, 0);
                slideInAnimation.addAnimation(translateAnimation);
                searchItemView.startAnimation(slideInAnimation);
              }
            }
          });
      animationLength = list.getChildCount() * 100 + 50;
      Log.d("Explorer animation", "CreateAnimator: return");
    } else if (nextAnim == R.animator.picker_fragment_explorer_out) {
      for (int i = 0; i < list.getChildCount(); i++) {
        View searchItemView = list.getChildAt(i);
        AnimationSet slideInAnimation = new AnimationSet(true);
        slideInAnimation.setInterpolator(new MaterialInterpolator());
        slideInAnimation.setDuration(100);
        slideInAnimation.setStartOffset(i * 50);
        slideInAnimation.setFillAfter(true);
        AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
        alphaAnimation.setFillAfter(true);
        slideInAnimation.addAnimation(alphaAnimation);
        TranslateAnimation translateAnimation = new TranslateAnimation(0, 100, 0, 0);
        slideInAnimation.addAnimation(translateAnimation);
        searchItemView.startAnimation(slideInAnimation);
      }
      if (items.size() == 1) {
        AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
        alphaAnimation.setInterpolator(new MaterialInterpolator());
        alphaAnimation.setDuration(100);
        alphaAnimation.setFillAfter(true);
        emptyView.startAnimation(alphaAnimation);
        statusView.startAnimation(alphaAnimation);
        animationLength = 250;
      } // else
      animationLength = 0; // list.getChildCount() * 100 + 50;
      Log.d("Explorer animation", "CreateAnimator: out");
    }

    AnimatorSet animator =
        (AnimatorSet)
            AnimatorInflater.loadAnimator(
                pickerActivity, R.animator.picker_fragment_explorer_enter);
    animator.setDuration(animationLength);

    return animator;
  }
Ejemplo n.º 18
0
  public void getTweets() {
    // tweetText.setText("");
    String queryText = keyword.getText().toString();
    if (queryText.matches("")) {
      Toast.makeText(this, "Please enter something", Toast.LENGTH_SHORT).show();
      return;
    }
    // System.out.println("Keyword =="+ queryText);
    if (isConnected()) {

      String oauthAccessToken = mSharedPreferences.getString(Const.PREF_KEY_TOKEN, "");
      String oAuthAccessTokenSecret = mSharedPreferences.getString(Const.PREF_KEY_SECRET, "");

      ConfigurationBuilder confbuilder = new ConfigurationBuilder();
      Configuration conf =
          confbuilder
              .setOAuthConsumerKey(Const.CONSUMER_KEY)
              .setOAuthConsumerSecret(Const.CONSUMER_SECRET)
              .setOAuthAccessToken(oauthAccessToken)
              .setOAuthAccessTokenSecret(oAuthAccessTokenSecret)
              .build();
      TwitterFactory tf = new TwitterFactory(conf);
      Twitter twitter = tf.getInstance();
      try {
        // Query query = new Query(queryText);

        int tweetCount = 50;
        User user = twitter.showUser(queryText.trim());
        long userId = user.getId();
        List<Status> tweets = twitter.getUserTimeline(userId, new Paging(1, tweetCount));

        // QueryResult result;
        // result = twitter.search(query);
        // List<Status> tweets = result.getTweets();
        String[] resultStringSet;
        if (tweets.size() == 0) {
          resultStringSet = new String[1];
          resultStringSet[0] = "No tweet found for this keyword. Please try some other keyword";
        } else {
          resultStringSet = new String[tweets.size()];
        }

        int i = 0;
        for (Status tweet : tweets) {
          final String text = "@" + tweet.getUser().getScreenName() + " - " + tweet.getText();
          // System.out.println(tweet);
          resultStringSet[i++] = text;
        }
        final ArrayAdapter<String> resultAdapter =
            new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, resultStringSet);
        list = (ListView) findViewById(R.id.resultList);
        list.post(
            new Runnable() {
              @Override
              public void run() {
                list.setAdapter(resultAdapter);

                // tweetText.append(text);
                // tweetText.append("\n");
                // scrollView.fullScroll(View.FOCUS_DOWN);
              }
            });

      } catch (TwitterException te) {
        Toast.makeText(
                this, "Please enter valid screen name of the twitter user", Toast.LENGTH_LONG)
            .show();
        te.printStackTrace();
        System.out.println("Failed to search tweets: " + te.getMessage());
        return;
        // System.exit(-1);
      }

      buttonLogin.setText(R.string.label_disconnect);
      getTweetButton.setEnabled(true);
    } else {
      buttonLogin.setText(R.string.label_connect);
    }
  }