Android Open Source - android_WallBox Themes Main Fragment






From Project

Back to project page android_WallBox.

License

The source code is released under:

Apache License

If you think the Android project android_WallBox 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 2014 Jeremie Long//from w  ww . j a v  a 2s  . c o m
 *
 * 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.lithidsw.wallbox.app.theme;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

import com.lithidsw.wallbox.R;
import com.lithidsw.wallbox.utils.C;

public class ThemesMainFragment extends Fragment {

    SharedPreferences prefs;
    FragmentActivity mActivity;
    View mLayout;
    SectionsPagerAdapter mSectionsPagerAdapter;
    ViewPager mViewPager;

    private int mChoosenTheme = -1;
    private static final int LIGHT_DARKACTIONBAR_THEME = 0;
    private static final int DARK_THEME = 1;
    private static final int LIGHT_THEME = 2;

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        mActivity = super.getActivity();
        prefs = mActivity.getSharedPreferences(C.PREF, Context.MODE_PRIVATE);
        mLayout = inflater.inflate(R.layout.themes_main_frag, container, false);
        if (mLayout != null) {
            prefs = mActivity.getSharedPreferences(C.PREF, Context.MODE_PRIVATE);
            mSectionsPagerAdapter = new SectionsPagerAdapter(getChildFragmentManager());
            mViewPager = (ViewPager) mLayout.findViewById(R.id.pager);
            mViewPager.setAdapter(mSectionsPagerAdapter);
            mViewPager.setCurrentItem(0);
            setHasOptionsMenu(true);
        }
        return mLayout;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.action_apply:
                mChoosenTheme = mViewPager.getCurrentItem();
                if (mChoosenTheme >= 0) {
                    onApplyClicked();
                }
                return true;
            default:
                return false;
        }
    }

    public void onApplyClicked() {
        Intent intent = mActivity.getIntent();
        intent.putExtra("open_themes_drawer", true);
        switch (mChoosenTheme) {
            case DARK_THEME:
                prefs.edit().putString(C.PREF_THEME, "Dark").commit();
                intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                mActivity.finish();
                startActivity(intent);
                break;
            case LIGHT_THEME:
                prefs.edit().putString(C.PREF_THEME, "Light").commit();
                intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                mActivity.finish();
                startActivity(intent);
                break;
            case LIGHT_DARKACTIONBAR_THEME:
                prefs.edit().putString(C.PREF_THEME, "LightDarkActionBar").commit();
                intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                mActivity.finish();
                startActivity(intent);
                break;
        }
    }

    public class SectionsPagerAdapter extends FragmentPagerAdapter {

        public SectionsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            Fragment fragment = new ThemeFragment();
            Bundle bundle = new Bundle();
            int[] theme = new int[2];
            switch (position) {
                case 0:
                    theme[0] = R.drawable.ic_preview_lightdarkactionbar;
                    theme[1] = R.drawable.ic_preview_lightdarkactionbar_land;
                    bundle.putIntArray("theme_preview", theme);
                    break;
                case 1:
                    theme[0] = R.drawable.ic_preview_dark;
                    theme[1] = R.drawable.ic_preview_dark_land;
                    bundle.putIntArray("theme_preview", theme);
                    break;
                case 2:
                    theme[0] = R.drawable.ic_preview_light;
                    theme[1] = R.drawable.ic_preview_light_land;
                    bundle.putIntArray("theme_preview", theme);
                    break;
            }
            fragment.setArguments(bundle);
            return fragment;
        }

        @Override
        public int getCount() {
            return 3;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
                case 0:
                    return "LightDarkActionBar";
                case 1:
                    return "Dark";
                case 2:
                    return "Light";
            }
            return null;
        }
    }
}




Java Source Code List

com.lithidsw.wallbox.AboutActivity.java
com.lithidsw.wallbox.ActionReceiver.java
com.lithidsw.wallbox.MainActivity.java
com.lithidsw.wallbox.app.colorwall.ColorWallFrag.java
com.lithidsw.wallbox.app.randomizer.RandomizerFrag.java
com.lithidsw.wallbox.app.randomizer.adapter.RandomizerGridAdapter.java
com.lithidsw.wallbox.app.randomizer.db.DBHelper.java
com.lithidsw.wallbox.app.randomizer.db.TableHelper.java
com.lithidsw.wallbox.app.saturate.SaturateFrag.java
com.lithidsw.wallbox.app.theme.ThemeFragment.java
com.lithidsw.wallbox.app.theme.ThemesMainFragment.java
com.lithidsw.wallbox.app.wallsnap.WallSnapActivity.java
com.lithidsw.wallbox.app.wallsnap.WallSnapFragment.java
com.lithidsw.wallbox.app.wallsnap.WallpaperFragment.java
com.lithidsw.wallbox.app.wallsnap.adapters.WallpaperAdapter.java
com.lithidsw.wallbox.loader.ImageLoader.java
com.lithidsw.wallbox.loader.MemoryCache.java
com.lithidsw.wallbox.utils.BitMapBlur.java
com.lithidsw.wallbox.utils.C.java
com.lithidsw.wallbox.utils.ColorFilterGenerator.java
com.lithidsw.wallbox.utils.ContribDialog.java
com.lithidsw.wallbox.utils.CustomDialogs.java
com.lithidsw.wallbox.utils.DateBuilder.java
com.lithidsw.wallbox.utils.JsonHelper.java
com.lithidsw.wallbox.utils.MenuHelper.java
com.lithidsw.wallbox.utils.Utils.java