/** * @param context The {@link Context} to use * @param attrs The attributes of the XML tag that is inflating the view. */ public ThemeableTextView(final Context context, final AttributeSet attrs) { super(context, attrs); // Initialze the theme resources final ThemeUtils resources = new ThemeUtils(context); // Retrieve styles attributes final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ThemeableTextView, 0, 0); // Get the theme resource name final String resourceName = typedArray.getString(R.styleable.ThemeableTextView_themeResource); // Theme the text color if (!TextUtils.isEmpty(resourceName)) { setTextColor(resources.getColor(resourceName)); } // Recyle the attrs typedArray.recycle(); }
/** * Constructor of <code>ImageWorker</code> * * @param context The {@link Context} to use */ protected ImageWorker(final Context context) { mContext = context.getApplicationContext(); mResources = mContext.getResources(); // Create the default artwork final ThemeUtils theme = new ThemeUtils(context); mDefault = ((BitmapDrawable) theme.getDrawable("default_artwork")).getBitmap(); mDefaultArtwork = new BitmapDrawable(mResources, mDefault); // No filter and no dither makes things much quicker mDefaultArtwork.setFilterBitmap(false); mDefaultArtwork.setDither(false); // Create the transparent layer for the transition drawable mCurrentDrawable = new ColorDrawable(mResources.getColor(R.color.transparent)); // A transparent image (layer 0) and the new result (layer 1) mArrayDrawable = new Drawable[2]; mArrayDrawable[0] = mCurrentDrawable; // XXX The second layer is set in the worker task. }
/** {@inheritDoc} */ @Override public boolean onCreateOptionsMenu(final Menu menu) { // Search view getSupportMenuInflater().inflate(R.menu.search, menu); // Theme the search icon mResources.setSearchIcon(menu); // Filter the list the user is looking it via SearchView mSearchView = (SearchView) menu.findItem(R.id.menu_search).getActionView(); mSearchView.setOnQueryTextListener(this); // Add voice search final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); final SearchableInfo searchableInfo = searchManager.getSearchableInfo(getComponentName()); mSearchView.setSearchableInfo(searchableInfo); return super.onCreateOptionsMenu(menu); }
/** {@inheritDoc} */ @Override public boolean onQueryTextSubmit(final String query) { if (TextUtils.isEmpty(query)) { return false; } // When the search is "committed" by the user, then hide the keyboard so // the user can // more easily browse the list of results. if (mSearchView != null) { final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) { imm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0); } mSearchView.clearFocus(); } // Action bar subtitle mResources.setSubtitle("\"" + mFilterString + "\""); return true; }
/** {@inheritDoc} */ @SuppressWarnings("deprecation") @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Title bar shows up in gingerbread, I'm too tired to figure out why. if (!ApolloUtils.hasHoneycomb()) { requestWindowFeature(Window.FEATURE_NO_TITLE); } // Initialze the theme resources mResources = new ThemeUtils(this); // Set the overflow style mResources.setOverflowStyle(this); // Fade it in overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); // Control the media volume setVolumeControlStream(AudioManager.STREAM_MUSIC); // Bind Apollo's service mToken = MusicUtils.bindToService(this, this); // Theme the action bar final ActionBar actionBar = getSupportActionBar(); mResources.themeActionBar(actionBar, getString(R.string.app_name)); actionBar.setDisplayHomeAsUpEnabled(true); // Set the layout setContentView(R.layout.grid_base); // Give the background a little UI final FrameLayout background = (FrameLayout) findViewById(R.id.grid_base_container); background.setBackgroundDrawable(getResources().getDrawable(R.drawable.pager_background)); // Get the query final String query = getIntent().getStringExtra(SearchManager.QUERY); mFilterString = !TextUtils.isEmpty(query) ? query : null; // Action bar subtitle mResources.setSubtitle("\"" + mFilterString + "\""); // Initialize the adapter mAdapter = new SearchAdapter(this); // Set the prefix mAdapter.setPrefix(mFilterString); // Initialze the list mGridView = (GridView) findViewById(R.id.grid_base); // Bind the data mGridView.setAdapter(mAdapter); // Recycle the data mGridView.setRecyclerListener(new RecycleHolder()); // Seepd up scrolling mGridView.setOnScrollListener(this); mGridView.setOnItemClickListener(this); if (ApolloUtils.isLandscape(this)) { mGridView.setNumColumns(TWO); } else { mGridView.setNumColumns(ONE); } // Prepare the loader. Either re-connect with an existing one, // or start a new one. getSupportLoaderManager().initLoader(0, null, this); }
/** {@inheritDoc} */ @Override public void onPrepareOptionsMenu(final Menu menu) { super.onPrepareOptionsMenu(menu); mResources.setFavoriteIcon(menu); }