Example usage for android.widget ViewSwitcher setOutAnimation

List of usage examples for android.widget ViewSwitcher setOutAnimation

Introduction

In this page you can find the example usage for android.widget ViewSwitcher setOutAnimation.

Prototype

public void setOutAnimation(Animation outAnimation) 

Source Link

Document

Specifies the animation used to animate a View that exit the screen.

Usage

From source file:io.github.trulyfree.easyaspi.MainActivity.java

@Override
public boolean setup() {
    downloadHandler = new DownloadHandler(this);
    fileHandler = new FileHandler(this);
    moduleHandler = new ModuleHandler(this);
    executorService = Executors.newCachedThreadPool();

    setContentView(R.layout.activity_main);
    BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
    navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {

        @Override//from  w  w w.ja va 2s .  com
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            ViewSwitcher viewGroup = (ViewSwitcher) findViewById(R.id.content);
            int id = item.getItemId();
            if ((id == R.id.navigation_home || id == R.id.navigation_modules) && id != currentID) {
                currentID = item.getItemId();
                viewGroup.showNext();
                return true;
            }
            return false;
        }

    });

    ViewSwitcher viewSwitcher = (ViewSwitcher) findViewById(R.id.content);
    Animation in = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left);
    Animation out = AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right);
    viewSwitcher.setInAnimation(in);
    viewSwitcher.setOutAnimation(out);

    resetConfigReturned();

    Button getNewModule = (Button) findViewById(R.id.new_module_config_confirm);
    getNewModule.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            EditText editText = (EditText) findViewById(R.id.new_module_config_configurl);
            final String url = editText.getText().toString();
            Toast.makeText(MainActivity.this, "Requested config from: " + url, Toast.LENGTH_SHORT).show();
            executorService.submit(new Callable<Boolean>() {
                @Override
                public Boolean call() {
                    ModuleConfig config;
                    try {
                        config = moduleHandler.getModuleConfig(url);
                    } catch (MalformedURLException e) {
                        e.printStackTrace();
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(MainActivity.this, "Invalid URL. :(", Toast.LENGTH_LONG).show();
                            }
                        });
                        return false;
                    } catch (IOException e) {
                        e.printStackTrace();
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(MainActivity.this, "Failed to get module config. :(",
                                        Toast.LENGTH_LONG).show();
                            }
                        });
                        return false;
                    } catch (JsonParseException e) {
                        e.printStackTrace();
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(MainActivity.this, "Config loaded was invalid. :(",
                                        Toast.LENGTH_LONG).show();
                            }
                        });
                        return false;
                    }

                    final ModuleConfig finalConfig = config;
                    final ImageView configResponseBlock = (ImageView) findViewById(R.id.block_module_returned);
                    final int colorFrom = ContextCompat.getColor(MainActivity.this, R.color.colorFillingTint);
                    final int colorTo = ContextCompat.getColor(MainActivity.this, R.color.colorClear);
                    final ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom,
                            colorTo);
                    colorAnimation.setDuration(ANIMATION_DURATION);
                    colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                        @Override
                        public void onAnimationUpdate(ValueAnimator animator) {
                            configResponseBlock.setBackgroundColor((Integer) animator.getAnimatedValue());
                        }
                    });
                    colorAnimation.addListener(new Animator.AnimatorListener() {
                        @Override
                        public void onAnimationStart(Animator animator) {
                        }

                        @Override
                        public void onAnimationEnd(Animator animator) {
                            LinearLayout layout = (LinearLayout) findViewById(R.id.module_returned_config);
                            EditText moduleName = (EditText) findViewById(R.id.module_returned_configname);
                            EditText moduleVersion = (EditText) findViewById(
                                    R.id.module_returned_configversion);
                            EditText moduleConfigUrl = (EditText) findViewById(R.id.module_returned_configurl);
                            EditText moduleJarUrl = (EditText) findViewById(R.id.module_returned_jarurl);
                            LinearLayout moduleDependencies = (LinearLayout) findViewById(
                                    R.id.module_returned_dependencies);
                            moduleDependencies.removeAllViewsInLayout();
                            try {
                                configResponseBlock.setVisibility(View.GONE);
                                moduleName.setText(finalConfig.getName());
                                moduleVersion.setText(finalConfig.getVersion());
                                moduleConfigUrl.setText(finalConfig.getConfUrl());
                                moduleJarUrl.setText(finalConfig.getJarUrl());
                                Config[] dependencies = finalConfig.getDependencies();
                                for (Config dependency : dependencies) {
                                    LinearLayout dependencyLayout = new LinearLayout(MainActivity.this);
                                    dependencyLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
                                            LayoutParams.WRAP_CONTENT));
                                    dependencyLayout.setOrientation(LinearLayout.HORIZONTAL);
                                    EditText name = new EditText(MainActivity.this);
                                    EditText jarUrl = new EditText(MainActivity.this);
                                    EditText[] loopThrough = { name, jarUrl };
                                    LayoutParams params = new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1.0f);
                                    for (EditText item : loopThrough) {
                                        item.setLayoutParams(params);
                                        item.setClickable(false);
                                        item.setInputType(InputType.TYPE_NULL);
                                        item.setCursorVisible(false);
                                        item.setFocusable(false);
                                        item.setFocusableInTouchMode(false);
                                    }
                                    name.setText(dependency.getName());
                                    jarUrl.setText(dependency.getJarUrl());
                                    dependencyLayout.addView(name);
                                    dependencyLayout.addView(jarUrl);
                                    moduleDependencies.addView(dependencyLayout);
                                }
                                layout.setClickable(true);
                                Button validate = (Button) findViewById(R.id.module_returned_validate);
                                Button cancel = (Button) findViewById(R.id.module_returned_cancel);
                                validate.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        Toast.makeText(MainActivity.this, "Requesting jars...",
                                                Toast.LENGTH_SHORT).show();
                                        executorService.submit(new Callable<Boolean>() {
                                            @Override
                                            public Boolean call() {
                                                try {
                                                    boolean success = true, refreshAllModification = true;
                                                    Button refreshAll = null,
                                                            getNewModule = (Button) findViewById(
                                                                    R.id.new_module_config_confirm);
                                                    try {
                                                        refreshAll = (Button) findViewById(R.id.refresh_all);
                                                        refreshAll.setClickable(false);
                                                    } catch (Throwable e) {
                                                        refreshAllModification = false;
                                                    }
                                                    getNewModule.setClickable(false);
                                                    final TextView stager = (TextView) findViewById(
                                                            R.id.new_module_config_downloadstage);
                                                    final ProgressBar progressBar = (ProgressBar) findViewById(
                                                            R.id.new_module_config_downloadprogress);
                                                    try {
                                                        runOnUiThread(new Runnable() {
                                                            @Override
                                                            public void run() {
                                                                resetConfigReturned();
                                                            }
                                                        });
                                                        moduleHandler.getNewModule(
                                                                makeModuleCallback(stager, progressBar),
                                                                finalConfig, null, true);
                                                    } catch (IOException e) {
                                                        e.printStackTrace();
                                                        runOnUiThread(new Runnable() {
                                                            @Override
                                                            public void run() {
                                                                stager.setText("");
                                                                progressBar.setProgress(0);
                                                            }
                                                        });
                                                        success = false;
                                                    }
                                                    getNewModule.setClickable(true);
                                                    if (refreshAllModification) {
                                                        refreshAll.setClickable(true);
                                                    }
                                                    return success;
                                                } catch (Throwable throwable) {
                                                    throwable.printStackTrace();
                                                    return false;
                                                }
                                            }
                                        });
                                    }
                                });
                                cancel.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        Toast.makeText(MainActivity.this, "Cancelling request...",
                                                Toast.LENGTH_SHORT).show();
                                        resetConfigReturned();
                                    }
                                });
                            } catch (Exception e) {
                                e.printStackTrace();
                                Toast.makeText(MainActivity.this, "Module config invalid. :(",
                                        Toast.LENGTH_LONG).show();
                                layout.setClickable(false);
                                final int colorFrom = ContextCompat.getColor(MainActivity.this,
                                        R.color.colorClear);
                                final int colorTo = ContextCompat.getColor(MainActivity.this,
                                        R.color.colorFillingTint);
                                ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
                                        colorFrom, colorTo);
                                colorAnimation.setDuration(ANIMATION_DURATION);
                                colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                                    @Override
                                    public void onAnimationUpdate(ValueAnimator animator) {
                                        configResponseBlock
                                                .setBackgroundColor((Integer) animator.getAnimatedValue());
                                    }
                                });
                            }
                        }

                        @Override
                        public void onAnimationCancel(Animator animator) {
                        }

                        @Override
                        public void onAnimationRepeat(Animator animator) {
                        }
                    });
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            colorAnimation.start();
                        }
                    });
                    return true;
                }
            });
        }
    });

    moduleHandler.setup();
    refreshFilling();
    return true;
}

From source file:de.baumann.thema.RequestActivity.java

@SuppressWarnings("unchecked")
private void populateView(ArrayList arrayListFinal) {
    ArrayList<AppInfo> local_arrayList;
    local_arrayList = arrayListFinal;/*from   w  ww .  j av a 2s.c  o m*/

    GridView grid = (GridView) findViewById(R.id.appgrid);

    assert grid != null;
    grid.setVerticalSpacing(GridView.AUTO_FIT);
    grid.setHorizontalSpacing(GridView.AUTO_FIT);
    grid.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
    grid.setFastScrollEnabled(true);
    grid.setFastScrollAlwaysVisible(true);

    if (DEBUG)
        Log.v(TAG, "height: " + getDisplaySize("height") + "; width: " + getDisplaySize("width"));

    AppAdapter appInfoAdapter;
    if (isPortrait()) {
        grid.setNumColumns(numCol_Portrait);

        if (isTablet(context)) {
            grid.setNumColumns(numCol_Portrait); //Here you can change the number of columns for Tablets
            if (DEBUG)
                Log.v(TAG, "isTablet");
        }
        if (isXLargeTablet(context)) {
            grid.setNumColumns(numCol_Portrait); //Here you can change the number of columns for Large Tablets
            if (DEBUG)
                Log.v(TAG, "isXLargeTablet");
        }

        appInfoAdapter = new AppAdapter(this, R.layout.request_item_list, local_arrayList);
    }

    else {
        grid.setNumColumns(numCol_Landscape);

        if (isTablet(context)) {
            grid.setNumColumns(numCol_Landscape); //Here you can change the number of columns for Tablets
            if (DEBUG)
                Log.v(TAG, "isTablet");
        }
        if (isXLargeTablet(context)) {
            grid.setNumColumns(numCol_Landscape); //Here you can change the number of columns for Large Tablets
            if (DEBUG)
                Log.v(TAG, "isXLargeTablet");
        }

        appInfoAdapter = new AppAdapter(this, R.layout.request_item_grid, local_arrayList);
    }

    grid.setAdapter(appInfoAdapter);
    grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> AdapterView, View view, int position, long row) {
            AppInfo appInfo = (AppInfo) AdapterView.getItemAtPosition(position);
            CheckBox checker = (CheckBox) view.findViewById(R.id.CBappSelect);
            ViewSwitcher icon = (ViewSwitcher) view.findViewById(R.id.viewSwitcherChecked);
            LinearLayout localBackground = (LinearLayout) view.findViewById(R.id.card_bg);
            Animation aniIn = AnimationUtils.loadAnimation(context, R.anim.request_flip_in_half_1);
            Animation aniOut = AnimationUtils.loadAnimation(context, R.anim.request_flip_in_half_2);

            checker.toggle();
            appInfo.setSelected(checker.isChecked());

            icon.setInAnimation(aniIn);
            icon.setOutAnimation(aniOut);

            if (appInfo.isSelected()) {
                if (DEBUG)
                    Log.v(TAG, "Selected App: " + appInfo.getName());
                localBackground
                        .setBackgroundColor(ContextCompat.getColor(context, R.color.request_card_pressed));
                if (icon.getDisplayedChild() == 0) {
                    icon.showNext();
                }
            } else {
                if (DEBUG)
                    Log.v(TAG, "Deselected App: " + appInfo.getName());
                localBackground
                        .setBackgroundColor(ContextCompat.getColor(context, R.color.request_card_unpressed));
                if (icon.getDisplayedChild() == 1) {
                    icon.showPrevious();
                }
            }
        }
    });
}