Example usage for android.view.animation AlphaAnimation setDuration

List of usage examples for android.view.animation AlphaAnimation setDuration

Introduction

In this page you can find the example usage for android.view.animation AlphaAnimation setDuration.

Prototype

public void setDuration(long durationMillis) 

Source Link

Document

How long this animation should last.

Usage

From source file:com.xmobileapp.rockplayer.RockPlayer.java

/********************************
 * /*from w ww.j a  v  a  2  s  .c  o  m*/
 * switch between different UI modes
 * 
 ********************************/
public void setNormalView() {
    if (VIEW_STATE == NORMAL_VIEW) {

    } else if (VIEW_STATE == LIST_EXPANDED_VIEW) {
        /*
         * Animate fading of the current playing layout
         */

        /*
         * Put album navigator full screen (this will happen in the end of the animation)
         */
        RelativeLayout.LayoutParams params = (LayoutParams) albumNavigatorLayoutOuter.getLayoutParams();
        params.addRule(RelativeLayout.RIGHT_OF, R.id.songfest_current_playing_container);
        albumNavigatorLayoutOuter.setLayoutParams(params);

        /*
         * Animate growth of the album navigator
         */
        int slideAmount = currentPlayingLayout.getWidth();
        albumNavigatorLayoutOuter.bringToFront();
        TranslateAnimation slideRight = new TranslateAnimation(-slideAmount, 0, 0, 0);
        slideRight.setFillAfter(true);
        slideRight.setDuration(250);
        slideRight.setAnimationListener(slideRightAnimationListener);
        albumNavigatorLayoutOuter.startAnimation(slideRight);

    } else if (VIEW_STATE == FULLSCREEN_VIEW) {

        setBackground();

        AlphaAnimation fadeOut = new AlphaAnimation(1.0f, 0.0f);
        fadeOut.setFillAfter(true);
        fadeOut.setDuration(300);
        this.mainUIContainer.startAnimation(fadeOut);

        showFullScreenHandler.sendEmptyMessageDelayed(VIEW_STATE, 300);

        VIEW_STATE = FULLSCREEN_VIEW;

    }

    VIEW_STATE = NORMAL_VIEW;
    return;
}

From source file:com.xmobileapp.rockplayer.RockPlayer.java

public void setFullScreenView() {

    Log.i("GOGO", "FULL SCREEN");

    hideBackground();/*  w  w  w .  j a va2  s .  c o m*/

    AlphaAnimation fadeOut = new AlphaAnimation(1.0f, 0.0f);
    fadeOut.setFillAfter(true);
    fadeOut.setDuration(300);
    this.mainUIContainer.startAnimation(fadeOut);

    showFullScreenHandler.sendEmptyMessageDelayed(NORMAL_VIEW, 300);

    VIEW_STATE = FULLSCREEN_VIEW;

    if (true)
        return;

    /*
     * Animate fading of the album navigator
     */
    Rotate3dAnimation perspectiveFullLeft = new Rotate3dAnimation(0, 0, // X-axis rotation
            90, 90, // Y-axis rotation
            0, 0, // Z-axis rotation
            100, 100, // rotation center
            0.0f, // Z-depth
            false); //reverse movement
    perspectiveFullLeft.setFillAfter(true);
    perspectiveFullLeft.setDuration(1);
    albumNavigatorList.startAnimation(perspectiveFullLeft);
    //       currentPlayingLayout.startAnimation(perspectiveFullLeft);

    /*
     * Put album navigator full screen
     */
    RelativeLayout.LayoutParams params = (LayoutParams) currentPlayingLayout.getLayoutParams();
    params.width = RelativeLayout.LayoutParams.FILL_PARENT;
    currentPlayingLayout.setLayoutParams(params);

    /*
     * Animate growth of the current playing layout
     */
    //      int fullWidth = display.getWidth();
    ////      int slideAmount = display.getWidth() - albumNavigatorList.getWidth();
    ////      TranslateAnimation slideLeft= new TranslateAnimation(slideAmount, 0, 0, 0);
    //      ScaleAnimation scaleAnim = new ScaleAnimation(0.66f, 1.0f, 1.0f, 1.0f);
    //      scaleAnim.setFillAfter(true);
    //      scaleAnim.setDuration(400);
    //      currentPlayingLayout.startAnimation(scaleAnim);

    //albumNavigatorLayout.setBackgroundColor(Color.WHITE);
    //         
    //         LayoutParams paramsList = (LayoutParams) albumNavigatorList.getLayoutParams();
    //         paramsList.width = display.getWidth();
    //         albumNavigatorList.setLayoutParams(paramsList);

    //      currentPlayingLayout.setVisibility(View.GONE);

    //      if(VIEW_STATE == NORMAL_VIEW){
    //         
    //         
    //         
    //      } else if(VIEW_STATE == LIST_EXPANDED_VIEW) {
    //         
    //      } else if(VIEW_STATE == FULLSCREEN_VIEW){
    //         
    //      }

    VIEW_STATE = FULLSCREEN_VIEW;
}

From source file:com.irccloud.android.activity.MainActivity.java

@Override
public void onBufferSelected(int bid) {
    launchBid = -1;/*www  .  ja va  2s .c  om*/
    launchURI = null;
    cidToOpen = -1;
    bufferToOpen = null;
    setIntent(new Intent(this, MainActivity.class));

    if (suggestionsTimerTask != null)
        suggestionsTimerTask.cancel();
    sortedChannels = null;
    sortedUsers = null;

    if (drawerLayout != null) {
        drawerLayout.closeDrawers();
    }
    if (bid != -1 && conn != null && conn.getUserInfo() != null) {
        conn.getUserInfo().last_selected_bid = bid;
    }
    for (int i = 0; i < backStack.size(); i++) {
        if (buffer != null && backStack.get(i) == buffer.bid)
            backStack.remove(i);
    }
    if (buffer != null && buffer.bid >= 0 && bid != buffer.bid) {
        backStack.add(0, buffer.bid);
        buffer.draft = messageTxt.getText().toString();
    }
    if (buffer == null || buffer.bid == -1 || buffer.cid == -1 || buffer.bid == bid)
        shouldFadeIn = false;
    else
        shouldFadeIn = true;
    buffer = BuffersDataSource.getInstance().getBuffer(bid);
    if (buffer != null) {
        Crashlytics.log(Log.DEBUG, "IRCCloud",
                "Buffer selected: cid" + buffer.cid + " bid" + bid + " shouldFadeIn: " + shouldFadeIn);
        server = ServersDataSource.getInstance().getServer(buffer.cid);

        try {
            TreeMap<Long, EventsDataSource.Event> events = EventsDataSource.getInstance()
                    .getEventsForBuffer(buffer.bid);
            if (events != null) {
                events = (TreeMap<Long, EventsDataSource.Event>) events.clone();
                for (EventsDataSource.Event e : events.values()) {
                    if (e != null && e.highlight && e.from != null) {
                        UsersDataSource.User u = UsersDataSource.getInstance().getUser(buffer.bid, e.from);
                        if (u != null && u.last_mention < e.eid)
                            u.last_mention = e.eid;
                    }
                }
            }
        } catch (Exception e) {
            Crashlytics.logException(e);
        }

        try {
            if (Build.VERSION.SDK_INT >= 16 && buffer != null && server != null) {
                NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);
                if (nfc != null) {
                    String uri = "irc";
                    if (server.ssl > 0)
                        uri += "s";
                    uri += "://" + server.hostname + ":" + server.port;
                    if (buffer.type.equals("channel")) {
                        uri += "/" + URLEncoder.encode(buffer.name, "UTF-8");
                        ChannelsDataSource.Channel c = ChannelsDataSource.getInstance()
                                .getChannelForBuffer(buffer.bid);
                        if (c != null && c.hasMode("k"))
                            uri += "," + c.paramForMode("k");
                    }
                    nfc.setNdefPushMessage(new NdefMessage(NdefRecord.createUri(uri)), this);
                }
            }
        } catch (Exception e) {
        }
    } else {
        Crashlytics.log(Log.DEBUG, "IRCCloud",
                "Buffer selected but not found: bid" + bid + " shouldFadeIn: " + shouldFadeIn);
        server = null;
    }
    update_subtitle();
    final Bundle b = new Bundle();
    if (buffer != null)
        b.putInt("cid", buffer.cid);
    b.putInt("bid", bid);
    b.putBoolean("fade", shouldFadeIn);
    BuffersListFragment blf = (BuffersListFragment) getSupportFragmentManager()
            .findFragmentById(R.id.BuffersList);
    final MessageViewFragment mvf = (MessageViewFragment) getSupportFragmentManager()
            .findFragmentById(R.id.messageViewFragment);
    UsersListFragment ulf = (UsersListFragment) getSupportFragmentManager()
            .findFragmentById(R.id.usersListFragment);
    UsersListFragment ulf2 = (UsersListFragment) getSupportFragmentManager()
            .findFragmentById(R.id.usersListFragment2);
    if (mvf != null)
        mvf.ready = false;
    if (blf != null)
        blf.setSelectedBid(bid);
    if (ulf != null)
        ulf.setArguments(b);
    if (ulf2 != null)
        ulf2.setArguments(b);

    if (shouldFadeIn) {
        Crashlytics.log(Log.DEBUG, "IRCCloud", "Fade Out");
        if (Build.VERSION.SDK_INT < 16) {
            AlphaAnimation anim = new AlphaAnimation(1, 0);
            anim.setDuration(150);
            anim.setFillAfter(true);
            anim.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {

                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    if (mvf != null)
                        mvf.setArguments(b);
                    messageTxt.setText("");
                    if (buffer != null && buffer.draft != null)
                        messageTxt.append(buffer.draft);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            });
            try {
                mvf.getListView().startAnimation(anim);
                ulf.getListView().startAnimation(anim);
            } catch (Exception e) {

            }
        } else {
            mvf.getListView().animate().alpha(0).withEndAction(new Runnable() {
                @Override
                public void run() {
                    if (mvf != null)
                        mvf.setArguments(b);
                    messageTxt.setText("");
                    if (buffer != null && buffer.draft != null)
                        messageTxt.append(buffer.draft);
                }
            });
            ulf.getListView().animate().alpha(0);
        }
        mvf.showSpinner(true);
    } else {
        if (mvf != null)
            mvf.setArguments(b);
        messageTxt.setText("");
        if (buffer != null && buffer.draft != null)
            messageTxt.append(buffer.draft);
    }

    updateUsersListFragmentVisibility();
    supportInvalidateOptionsMenu();
    if (excludeBIDTask != null)
        excludeBIDTask.cancel(true);
    excludeBIDTask = new ExcludeBIDTask();
    excludeBIDTask.execute(bid);
    if (drawerLayout != null)
        new RefreshUpIndicatorTask().execute((Void) null);
    if (buffer != null && buffer.cid != -1) {
        if (drawerLayout != null) {
            drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.LEFT);
            getSupportActionBar().setHomeButtonEnabled(true);
        }
    }
    update_suggestions(false);
}

From source file:com.irccloud.android.activity.MainActivity.java

private void update_suggestions(boolean force) {
    if (buffer != null && suggestionsContainer != null && messageTxt != null && messageTxt.getText() != null) {
        String text;//from   ww w  .  j a  v a 2  s  . co m
        try {
            text = messageTxt.getText().toString();
        } catch (Exception e) {
            text = "";
        }
        if (text.lastIndexOf(' ') > 0 && text.lastIndexOf(' ') < text.length() - 1) {
            text = text.substring(text.lastIndexOf(' ') + 1);
        }
        if (text.endsWith(":"))
            text = text.substring(0, text.length() - 1);
        text = text.toLowerCase();
        final ArrayList<String> sugs = new ArrayList<String>();
        HashSet<String> sugs_set = new HashSet<String>();
        if (text.length() > 2 || force || (text.length() > 0 && suggestionsAdapter.activePos != -1)) {
            ArrayList<ChannelsDataSource.Channel> channels = sortedChannels;
            if (channels == null) {
                channels = ChannelsDataSource.getInstance().getChannels();
                Collections.sort(channels, new Comparator<ChannelsDataSource.Channel>() {
                    @Override
                    public int compare(ChannelsDataSource.Channel lhs, ChannelsDataSource.Channel rhs) {
                        return lhs.name.compareTo(rhs.name);
                    }
                });

                sortedChannels = channels;
            }

            if (buffer != null && messageTxt.getText().length() > 0 && buffer.type.equals("channel")
                    && buffer.name.toLowerCase().startsWith(text) && !sugs_set.contains(buffer.name)) {
                sugs_set.add(buffer.name);
                sugs.add(buffer.name);
            }
            if (channels != null) {
                for (ChannelsDataSource.Channel channel : channels) {
                    if (text.length() > 0 && text.charAt(0) == channel.name.charAt(0)
                            && channel.name.toLowerCase().startsWith(text)
                            && !sugs_set.contains(channel.name)) {
                        sugs_set.add(channel.name);
                        sugs.add(channel.name);
                    }
                }
            }

            JSONObject disableAutoSuggest = null;
            if (NetworkConnection.getInstance().getUserInfo() != null
                    && NetworkConnection.getInstance().getUserInfo().prefs != null) {
                try {
                    if (NetworkConnection.getInstance().getUserInfo().prefs.has("channel-disableAutoSuggest"))
                        disableAutoSuggest = NetworkConnection.getInstance().getUserInfo().prefs
                                .getJSONObject("channel-disableAutoSuggest");
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }

            boolean disabled;
            try {
                disabled = disableAutoSuggest != null && disableAutoSuggest.has(String.valueOf(buffer.bid))
                        && disableAutoSuggest.getBoolean(String.valueOf(buffer.bid));
            } catch (JSONException e) {
                disabled = false;
            }

            ArrayList<UsersDataSource.User> users = sortedUsers;
            if (users == null && buffer != null && (force || !disabled)) {
                users = UsersDataSource.getInstance().getUsersForBuffer(buffer.bid);
                if (users != null) {
                    Collections.sort(users, new Comparator<UsersDataSource.User>() {
                        @Override
                        public int compare(UsersDataSource.User lhs, UsersDataSource.User rhs) {
                            if (lhs.last_mention > rhs.last_mention)
                                return -1;
                            if (lhs.last_mention < rhs.last_mention)
                                return 1;
                            return lhs.nick.compareToIgnoreCase(rhs.nick);
                        }
                    });
                }
                sortedUsers = users;
            }
            if (users != null) {
                for (UsersDataSource.User user : users) {
                    String nick = user.nick_lowercase;
                    if (text.matches("^[a-zA-Z0-9]+.*"))
                        nick = nick.replaceFirst("^[^a-zA-Z0-9]+", "");

                    if (nick.startsWith(text) && !sugs_set.contains(user.nick)) {
                        sugs_set.add(user.nick);
                        sugs.add(user.nick);
                    }
                }
            }
        }

        if (Build.VERSION.SDK_INT >= 14 && text.startsWith(":") && text.length() > 1) {
            String q = text.toLowerCase().substring(1);
            for (String emocode : ColorFormatter.emojiMap.keySet()) {
                if (emocode.startsWith(q)) {
                    String emoji = ColorFormatter.emojiMap.get(emocode);
                    if (!sugs_set.contains(emoji)) {
                        sugs_set.add(emoji);
                        sugs.add(emoji);
                    }
                }
            }
        }

        if (sugs.size() == 0 && suggestionsContainer.getVisibility() == View.INVISIBLE)
            return;

        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (sugs.size() > 0) {
                    if (suggestionsAdapter.activePos == -1) {
                        suggestionsAdapter.clear();
                        for (String s : sugs) {
                            suggestionsAdapter.add(s);
                        }
                        suggestionsAdapter.notifyDataSetChanged();
                        suggestions.smoothScrollToPosition(0);
                    }
                    if (suggestionsContainer.getVisibility() == View.INVISIBLE) {
                        if (Build.VERSION.SDK_INT < 16) {
                            AlphaAnimation anim = new AlphaAnimation(0, 1);
                            anim.setDuration(250);
                            anim.setFillAfter(true);
                            suggestionsContainer.startAnimation(anim);
                        } else {
                            suggestionsContainer.setAlpha(0);
                            suggestionsContainer.setTranslationY(1000);
                            suggestionsContainer.animate().alpha(1).translationY(0)
                                    .setInterpolator(new DecelerateInterpolator());
                        }
                        suggestionsContainer.setVisibility(View.VISIBLE);
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                if (suggestionsContainer.getHeight() < 48) {
                                    getSupportActionBar().hide();
                                }
                            }
                        });
                    }
                } else {
                    if (suggestionsContainer.getVisibility() == View.VISIBLE) {
                        if (Build.VERSION.SDK_INT < 16) {
                            AlphaAnimation anim = new AlphaAnimation(1, 0);
                            anim.setDuration(250);
                            anim.setFillAfter(true);
                            anim.setAnimationListener(new Animation.AnimationListener() {
                                @Override
                                public void onAnimationStart(Animation animation) {

                                }

                                @Override
                                public void onAnimationEnd(Animation animation) {
                                    suggestionsContainer.setVisibility(View.INVISIBLE);
                                    suggestionsAdapter.clear();
                                    suggestionsAdapter.notifyDataSetChanged();
                                }

                                @Override
                                public void onAnimationRepeat(Animation animation) {

                                }
                            });
                            suggestionsContainer.startAnimation(anim);
                        } else {
                            suggestionsContainer.animate().alpha(1).translationY(1000)
                                    .setInterpolator(new AccelerateInterpolator())
                                    .withEndAction(new Runnable() {
                                        @Override
                                        public void run() {
                                            suggestionsContainer.setVisibility(View.INVISIBLE);
                                            suggestionsAdapter.clear();
                                            suggestionsAdapter.notifyDataSetChanged();
                                        }
                                    });
                        }
                        sortedUsers = null;
                        sortedChannels = null;
                        if (!getSupportActionBar().isShowing())
                            getSupportActionBar().show();
                    }
                }
            }
        });
    }
}