Android Open Source - FxExplorer Theme Chooser Activity






From Project

Back to project page FxExplorer.

License

The source code is released under:

Apache License

If you think the Android project FxExplorer 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

package info.breezes.fxmanager;
/*from w ww .ja v a2  s.  c o m*/
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.ArrayList;

import info.breezes.PreferenceUtil;
import info.breezes.SecretPreferenceUtil;
import info.breezes.fxmanager.countly.CountlyActivity;
import info.breezes.toolkit.ui.LayoutViewHelper;
import info.breezes.toolkit.ui.annotation.LayoutView;


public class ThemeChooserActivity extends CountlyActivity {

    @LayoutView(R.id.recyclerView)
    private RecyclerView recyclerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_theme_chooser);
        LayoutViewHelper.initLayout(this);
        setupSupportActionBar();
        GridLayoutManager layoutManager = new GridLayoutManager(this, 2);
        layoutManager.setOrientation(GridLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);
        setupActionBar();
        ArrayList<ThemeItem> themes = new ArrayList<>();
        themes.add(new ThemeItem(getString(R.string.red), R.drawable.theme_p_r, R.style.AppTheme_Red));
        themes.add(new ThemeItem(getString(R.string.blue), R.drawable.theme_p_b, R.style.AppTheme_Blue));
        themes.add(new ThemeItem(getString(R.string.purple), R.drawable.theme_p_p, R.style.AppTheme_Purple));
        themes.add(new ThemeItem(getString(R.string.green), R.drawable.theme_p_g, R.style.AppTheme_Green));
        themes.add(new ThemeItem(getString(R.string.yellow), R.drawable.theme_p_y, R.style.AppTheme_Yellow));
        recyclerView.setAdapter(new ThemesAdapter(this, themes));
    }

    private void setupActionBar() {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }


    class ThemeItem {
        public int preview;
        public int type;
        public String title;

        public ThemeItem(String title, int preview, int type) {
            this.title = title;
            this.preview = preview;
            this.type = type;
        }
    }

    class ThemesAdapter extends RecyclerView.Adapter<ThemesAdapter.ThemeItemHolder> {
        private Context context;
        private ArrayList<ThemeItem> themes;
        private int checkedType;

        public ThemesAdapter(Context context, ArrayList<ThemeItem> themes) {
            this.context = context;
            this.themes = themes;
            checkedType = PreferenceUtil.findPreference(context, R.string.pref_key_theme, R.style.AppTheme_Blue);
        }

        @Override
        public ThemeItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            return new ThemeItemHolder(LayoutInflater.from(context).inflate(R.layout.theme_item, parent, false));
        }

        @Override
        public int getItemCount() {
            return themes == null ? 0 : themes.size();
        }

        @Override
        public void onBindViewHolder(ThemeItemHolder holder, int position) {
            holder.setThemeItem(themes.get(position));
        }

        class ThemeItemHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

            private ThemeItem themeItem;

            @LayoutView(R.id.imageView)
            private ImageView previewImage;
            @LayoutView(R.id.checkImageView)
            private ImageView checkImage;

            public ThemeItemHolder(View itemView) {
                super(itemView);
                LayoutViewHelper.initLayout(itemView, this);
                itemView.setOnClickListener(this);
            }

            public void setThemeItem(ThemeItem themeItem) {
                this.themeItem = themeItem;
                checkImage.setVisibility(themeItem.type == checkedType ? View.VISIBLE : View.GONE);
                previewImage.setImageResource(themeItem.preview);
            }

            @Override
            public void onClick(View v) {
                if (checkedType != themeItem.type) {
                    checkedType = themeItem.type;
                    ThemesAdapter.this.notifyDataSetChanged();
                    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                    SharedPreferences.Editor editor = preferences.edit();
                    editor.putInt(getString(R.string.pref_key_theme), themeItem.type);
                    editor.commit();
                    sendBroadcast(new Intent(ACTION_THEME_CHANGED));
                }
            }
        }
    }
}




Java Source Code List

info.breezes.fx.downloader.ApplicationTest.java
info.breezes.fx.downloader.DlMainActivity.java
info.breezes.fx.editor.ApplicationTest.java
info.breezes.fx.editor.EditorMainActivity.java
info.breezes.fx.player.ApplicationTest.java
info.breezes.fx.player.MainActivity.java
info.breezes.fx.viewer.ApplicationTest.java
info.breezes.fx.viewer.BigImageView.java
info.breezes.fx.viewer.ImageUtility.java
info.breezes.fx.viewer.MainActivity.java
info.breezes.fxmanager.ApplicationTest.java
info.breezes.fxmanager.FxApplication.java
info.breezes.fxmanager.LocalFileSystemProvider.java
info.breezes.fxmanager.MainActivity.java
info.breezes.fxmanager.MediaFragment.java
info.breezes.fxmanager.MediaItemUtil.java
info.breezes.fxmanager.MediaProvider.java
info.breezes.fxmanager.MenuAdapter.java
info.breezes.fxmanager.MimeTypeMap.java
info.breezes.fxmanager.NetUtils.java
info.breezes.fxmanager.PackagesProvider.java
info.breezes.fxmanager.ScanResultActivity.java
info.breezes.fxmanager.ScannerActivity.java
info.breezes.fxmanager.SettingsActivity.java
info.breezes.fxmanager.ShellUtil.java
info.breezes.fxmanager.StorageTool.java
info.breezes.fxmanager.ThemeChooserActivity.java
info.breezes.fxmanager.android.app.QAlertDialog.java
info.breezes.fxmanager.countly.CountlyActivity.java
info.breezes.fxmanager.countly.CountlyEvent.java
info.breezes.fxmanager.countly.CountlyFragment.java
info.breezes.fxmanager.countly.CountlyUtils.java
info.breezes.fxmanager.dialog.ApkInfoDialog.java
info.breezes.fxmanager.dialog.FileInfoDialog.java
info.breezes.fxmanager.dialog.HashInfoDialog.java
info.breezes.fxmanager.model.DrawerMenu.java
info.breezes.fxmanager.model.MediaItem.java
info.breezes.fxmanager.qrcode.QrBitmapDecoder.java
info.breezes.fxmanager.service.FileService.java
net.gescobar.httpserver.Handler.java
net.gescobar.httpserver.HttpConnection.java
net.gescobar.httpserver.HttpServer.java
net.gescobar.httpserver.Request.java
net.gescobar.httpserver.Response.java