Android Open Source - ImageLayout Fit Attribute Activity






From Project

Back to project page ImageLayout.

License

The source code is released under:

Apache License

If you think the Android project ImageLayout listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2013 Manuel Peinado/*from w w w . ja  va2s  .com*/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.manuelpeinado.imagelayout.demo;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import com.manuelpeinado.imagelayout.ImageLayout;

/**
 * This activity illustrates the different values accepted by the 
 * "custom:fit" attribute
 */
public class FitAttributeActivity extends Activity {

    private ImageLayout imageLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fit_attribute);
        imageLayout = (ImageLayout) findViewById(R.id.image_layout);
        initFitMode(savedInstanceState);
    }

    private void initFitMode(Bundle savedInstanceState) {
        int fitMode = imageLayout.getFitMode();
        if (savedInstanceState != null) {
            fitMode = savedInstanceState.getInt("fitMode", fitMode);
        }
        setFitMode(fitMode);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_fit_attribute, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() ==  R.id.fit_vertical) {
            setFitMode(ImageLayout.FIT_VERTICAL);
            return true;
        }
        if (item.getItemId() == R.id.fit_horizontal) {
            setFitMode(ImageLayout.FIT_HORIZONTAL);
            return true;
        }
        if (item.getItemId() == R.id.fit_auto) {
            setFitMode(ImageLayout.FIT_AUTO);
            return true;
        }
        if (item.getItemId() == R.id.fit_both) {
            setFitMode(ImageLayout.FIT_BOTH);
            return true;
        }
        return false;
    }

    private void setFitMode(int fitMode) {
        imageLayout.setFitMode(fitMode);
        updateTitle();
    }

    private void updateTitle() {
        switch (imageLayout.getFitMode()) {
        case ImageLayout.FIT_VERTICAL:
            setTitle(R.string.fit_vertical);
            return;
        case ImageLayout.FIT_HORIZONTAL:
            setTitle(R.string.fit_horizontal);
            return;
        case ImageLayout.FIT_AUTO:
            setTitle(R.string.fit_auto);
            return;
        case ImageLayout.FIT_BOTH:
            setTitle(R.string.fit_both);
            return;
        }
    }
    
    @Override
    protected void onSaveInstanceState(Bundle outState) {
        outState.putInt("fitMode", imageLayout.getFitMode());
    }
}




Java Source Code List

com.manuelpeinado.imagelayout.ImageFitter.java
com.manuelpeinado.imagelayout.ImageLayout.java
com.manuelpeinado.imagelayout.demo.ActivityInfo.java
com.manuelpeinado.imagelayout.demo.AddChildrenProgrammaticallyActivity.java
com.manuelpeinado.imagelayout.demo.BasicUsageActivity.java
com.manuelpeinado.imagelayout.demo.ChangeImageDynamicallyActivity.java
com.manuelpeinado.imagelayout.demo.FitAttributeActivity.java
com.manuelpeinado.imagelayout.demo.HomeActivity.java
com.manuelpeinado.imagelayout.demo.HorizontalScrollViewActivity.java