@Override public void onViewCreated(View view) { super.onViewCreated(view); GridView gridView = (GridView) view.findViewById(android.R.id.list); final ThemeUtils.ThemeValue[] values = ThemeUtils.ThemeValue.values(); int columnWidth = UiUtil.getDisplayWidth() / 2; if (columnWidth < 240) { columnWidth = 160; } else if (columnWidth < 320) { columnWidth = 240; } else if (columnWidth < 480) { columnWidth = 320; } else if (columnWidth < 720) { columnWidth = 480; } else if (columnWidth < 1080) { columnWidth = 720; } else { columnWidth = 1080; } ITracker.Impl.get(getActivity()).track("themes:width:" + columnWidth); final int finalImageWidth = columnWidth; gridView.setAdapter( new ArrayAdapter<ThemeUtils.ThemeValue>( getActivity(), R.layout.adapter_theme, android.R.id.text1, values) { @Override public View getView(int position, View convertView, ViewGroup parent) { View view = super.getView(position, convertView, parent); ImageView imageView = (ImageView) view.findViewById(R.id.icon); String path = "http://robust-window-94306.appspot.com/themes/" + finalImageWidth + "/" + values[position].name() + ".jpeg"; Picasso.with(getActivity()).load(path).into(imageView); return view; } }); gridView.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = new Intent(); intent.putExtra(ThemesActivity.EXTRA_THEME_ORDINAL_KEY, position); getActivity().setResult(Activity.RESULT_OK, intent); getActivity().finish(); } }); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); callbackManager.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_CODE_RESOLUTION) { mIntentInProgress = false; if (!mGoogleApiClient.isConnecting()) { mGoogleApiClient.connect(); } } else if (requestCode == REQUEST_CODE_THEME && resultCode == RESULT_OK) { ThemeUtils.ThemeValue themeValue = ThemeUtils.ThemeValue.values()[ data.getIntExtra(ThemesActivity.EXTRA_THEME_ORDINAL_KEY, 0)]; ITracker.Impl.get(this).track("theme:" + themeValue.name()); ThemeUtils.setTheme(this, themeValue); } else if (requestCode == REQUEST_CODE_PLUS) { mDrawerInitializer.refreshButtons(); } }