@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); overridePendingTransition(R.anim.fadein, R.anim.fadeout); // .................................... // Load state of filter from Bundle if (savedInstanceState != null) { mSeriesFilter = savedInstanceState.getString("mSeriesFilter"); mFilterMode = savedInstanceState.getInt("mFilterMode"); if (mSeriesFilter == null) mSeriesFilter = ""; // if no filter found } else { // if no state, load in default pref. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); String tmp = prefs.getString("libraryFilter", "0"); this.mFilterMode = Integer.parseInt(tmp); } // if // .................................... mThumbPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/OpenComicReader/thumbs/"; mSpinAdapter = new ArrayAdapter<String>( this, android.R.layout.simple_spinner_dropdown_item, this.getResources().getStringArray(R.array.libraryFilter)); // .................................... // Setup Actionbar ActionBar mActionBar = this.getActionBar(); mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); mActionBar.setDisplayShowTitleEnabled(false); mActionBar.setListNavigationCallbacks(mSpinAdapter, this); mActionBar.setSelectedNavigationItem(mFilterMode); mActionBar.setDisplayOptions( ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_HOME); mActionBar.setCustomView(R.layout.activity_main_actionbar); mCountLbl = (TextView) mActionBar.getCustomView().findViewById(R.id.lblCount); mSeriesLbl = (TextView) mActionBar.getCustomView().findViewById(R.id.lblSeries); // .................................... // Setup Main View Area mAdapter = new SqlCursorAdapter(this); mAdapter.setItemLayout(R.layout.listitem_main); mGridView = (GridView) findViewById(R.id.lvMain); mGridView.setAdapter(mAdapter); mGridView.setOnItemClickListener(this); registerForContextMenu(mGridView); // Route event from Activity to View // .................................... // Start DB and Data Loader mDb = new Sqlite(this); mDb.openRead(); getSupportLoaderManager().initLoader(0, null, this); } // func
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ActionBar actionBar = activity.getActionBar(); View view = actionBar.getCustomView(); ImageView title_image = (ImageView) view.findViewById(R.id.title_image); title_image.setBackgroundResource(R.drawable.substancea_cs); ScrollView sv = new ScrollView(activity); sv.setLayoutParams( new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); sv.setFillViewport(true); LinearLayout lay = new LinearLayout(activity); lay.setOrientation(LinearLayout.VERTICAL); lay.setBackgroundColor(Color.WHITE); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); sv.addView(lay, params); // setContentView(sv); search_lay.setOnClickListener(searchLis); search_btn.setOnClickListener(searchLis); showLinelay = new LinearLayout(activity); ((LinearLayout) showLinelay).setOrientation(LinearLayout.VERTICAL); lay.addView(showLinelay, params); initNet(); loadData(new RequestPram()); }
protected void init() { setContentView(R.layout.wallpaper_cropper); mCropView = (CropView) findViewById(R.id.cropView); Intent cropIntent = getIntent(); final Uri imageUri = cropIntent.getData(); if (imageUri == null) { Log.e(LOGTAG, "No URI passed in intent, exiting WallpaperCropActivity"); finish(); return; } int rotation = getRotationFromExif(this, imageUri); mCropView.setTileSource(new BitmapRegionTileSource(this, imageUri, 1024, rotation), null); mCropView.setTouchEnabled(true); // Action bar // Show the custom action bar view final ActionBar actionBar = getActionBar(); actionBar.setCustomView(R.layout.actionbar_set_wallpaper); actionBar .getCustomView() .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { boolean finishActivityWhenDone = true; cropImageAndSetWallpaper(imageUri, null, finishActivityWhenDone); } }); }
public void initActionBar() { ActionBar actionBar = getActionBar(); actionBar.setDisplayShowCustomEnabled(true); actionBar.setCustomView(R.layout.actionbar_main); actionBar.setDisplayUseLogoEnabled(false); actionBar.setDisplayShowHomeEnabled(false); View view = actionBar.getCustomView(); RelativeLayout exitBt = (RelativeLayout) view.findViewById(R.id.add_lay); }
/** 设置ActionBar标题内容 */ @Override public void setActionBarTitle(String title) { ActionBar actionBar = getActionBar(); if (actionBar != null) { TextView titleView = (TextView) actionBar.getCustomView(); // titleView.setTextColor(Color.WHITE); titleView.setText(title); } }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ActionBar actionBar = activity.getActionBar(); View view = actionBar.getCustomView(); ImageView title_image = (ImageView) view.findViewById(R.id.title_image); title_image.setBackgroundResource(R.drawable.departure_title); ; }
@Override public boolean onOptionsItemSelected(MenuItem item) { // TODO Auto-generated method stub switch (item.getItemId()) { case R.id.enterAmount: if (bar.getCustomView() != null) break; bar.setCustomView(R.layout.action_bar); bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME); final EditText money = (EditText) bar.getCustomView().findViewById(R.id.moneyEditText); final Button go = (Button) bar.getCustomView().findViewById(R.id.goButton); go.setOnClickListener( new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub hideKeyboard(); double price = 0; try { price = Double.parseDouble(money.getText().toString()); } catch (NumberFormatException e) { Toast.makeText(getApplicationContext(), "Invalid number", Toast.LENGTH_SHORT) .show(); return; } ll.setVisibility(View.VISIBLE); ll2.setVisibility(View.INVISIBLE); startService( new Intent(FoodList.this, FoodListService.class) .putExtra(UtilClass._basePrice, price)); bar.setCustomView(null); } }); break; } return super.onOptionsItemSelected(item); }
private static View initView(ActionBar actionBar, int viewId, OnClickListener onDone) { // Inflate a custom view and set a Done handler actionBar.setCustomView(viewId); View view = actionBar.getCustomView(); view.findViewById(R.id.actionbar_done).setOnClickListener(onDone); // Show the custom action bar view and hide the normal Home icon and title. actionBar.setDisplayShowTitleEnabled(false); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowCustomEnabled(true); return view; }
@SuppressWarnings("unchecked") protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_link); // Set up layout bridgesList = (ListView) findViewById(R.id.link_bridges); bridgesAdapter = new BridgeAdapter(this); bridgesList.setAdapter(bridgesAdapter); bridgesList.setEmptyView(findViewById(R.id.link_empty)); // Set up loading UI elements ActionBar ab = getActionBar(); ab.setCustomView(R.layout.loader); ab.setDisplayShowCustomEnabled(true); ab.setDisplayShowHomeEnabled(false); RelativeLayout loadingLayout = (RelativeLayout) ab.getCustomView(); loadingSpinner = (ProgressBar) loadingLayout.findViewById(R.id.loader_spinner); refreshButton = (ImageButton) loadingLayout.findViewById(R.id.loader_refresh); setEventHandlers(); // Restore state or start over if (savedInstanceState == null) { Bridge lastBridge = Util.getLastBridge(this); if (lastBridge != null) { // This will be set again after a successful connection, connection failure leaves the last // bridge null Util.setLastBridge(this, null); // Try connecting to last bridge connectToLastBridge(lastBridge); } else { // Start searching for bridges and add them to the results startSearching(true); } } else { bridges = (ArrayList<Bridge>) savedInstanceState.getSerializable("bridges"); for (Bridge b : bridges) { bridgesAdapter.add(b); } // If a search was running, continue without removing existing results if (savedInstanceState.getBoolean("searching")) { startSearching(false); } } }
protected void init() { setContentView(R.layout.wallpaper_cropper); mCropView = (CropView) findViewById(R.id.cropView); Intent cropIntent = getIntent(); final Uri imageUri = cropIntent.getData(); if (imageUri == null) { Log.e(LOGTAG, "No URI passed in intent, exiting WallpaperCropActivity"); finish(); return; } // Action bar // Show the custom action bar view final ActionBar actionBar = getActionBar(); actionBar.setCustomView(R.layout.actionbar_set_wallpaper); actionBar .getCustomView() .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { boolean finishActivityWhenDone = true; cropImageAndSetWallpaper(imageUri, null, finishActivityWhenDone); } }); mSetWallpaperButton = findViewById(R.id.set_wallpaper_button); // Load image in background final BitmapRegionTileSource.UriBitmapSource bitmapSource = new BitmapRegionTileSource.UriBitmapSource(this, imageUri, 1024); mSetWallpaperButton.setEnabled(false); Runnable onLoad = new Runnable() { public void run() { if (bitmapSource.getLoadingState() != BitmapSource.State.LOADED) { Toast.makeText( WallpaperCropActivity.this, getString(R.string.wallpaper_load_fail), Toast.LENGTH_LONG) .show(); finish(); } else { mSetWallpaperButton.setEnabled(true); } } }; setCropViewTileSource(bitmapSource, true, false, onLoad); }
private void openSearchBar(String queryText) { // Set custom view on action bar. ActionBar actionBar = getActionBar(); actionBar.setDisplayShowCustomEnabled(true); actionBar.setCustomView(R.layout.search_bar); // Search edit text field setup. mSearchEt = (EditText) actionBar.getCustomView().findViewById(R.id.etSearch); mSearchEt.addTextChangedListener(new SearchWatcher()); mSearchEt.setText(queryText); mSearchEt.requestFocus(); // open the soft keyboard ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)) .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); // Change search icon accordingly. mSearchAction.setIcon(mIconCloseSearch); mSearchOpened = true; }
@Override public View getCustomView() { return mActionBar.getCustomView(); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ImageFilterRS.setRenderScriptContext(this); ImageShow.setDefaultBackgroundColor(getResources().getColor(R.color.background_screen)); ImageSmallFilter.setDefaultBackgroundColor( getResources().getColor(R.color.background_main_toolbar)); // TODO: get those values from XML. ImageZoom.setZoomedSize(getPixelsFromDip(256)); FramedTextButton.setTextSize((int) getPixelsFromDip(14)); FramedTextButton.setTrianglePadding((int) getPixelsFromDip(4)); FramedTextButton.setTriangleSize((int) getPixelsFromDip(10)); ImageShow.setTextSize((int) getPixelsFromDip(12)); ImageShow.setTextPadding((int) getPixelsFromDip(10)); ImageShow.setOriginalTextMargin((int) getPixelsFromDip(4)); ImageShow.setOriginalTextSize((int) getPixelsFromDip(18)); ImageShow.setOriginalText(getResources().getString(R.string.original_picture_text)); ImageButtonTitle.setTextSize((int) getPixelsFromDip(12)); ImageButtonTitle.setTextPadding((int) getPixelsFromDip(10)); ImageSmallFilter.setMargin((int) getPixelsFromDip(3)); ImageSmallFilter.setTextMargin((int) getPixelsFromDip(4)); Drawable curveHandle = getResources().getDrawable(R.drawable.camera_crop); int curveHandleSize = (int) getResources().getDimension(R.dimen.crop_indicator_size); Spline.setCurveHandle(curveHandle, curveHandleSize); Spline.setCurveWidth((int) getPixelsFromDip(3)); setContentView(R.layout.filtershow_activity); ActionBar actionBar = getActionBar(); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); actionBar.setCustomView(R.layout.filtershow_actionbar); actionBar .getCustomView() .setOnClickListener( new OnClickListener() { @Override public void onClick(View view) { saveImage(); } }); mImageLoader = new ImageLoader(this, getApplicationContext()); LinearLayout listFilters = (LinearLayout) findViewById(R.id.listFilters); LinearLayout listBorders = (LinearLayout) findViewById(R.id.listBorders); LinearLayout listColors = (LinearLayout) findViewById(R.id.listColorsFx); mImageShow = (ImageShow) findViewById(R.id.imageShow); mImageCurves = (ImageCurves) findViewById(R.id.imageCurves); mImageBorders = (ImageBorder) findViewById(R.id.imageBorder); mImageStraighten = (ImageStraighten) findViewById(R.id.imageStraighten); mImageZoom = (ImageZoom) findViewById(R.id.imageZoom); mImageCrop = (ImageCrop) findViewById(R.id.imageCrop); mImageRotate = (ImageRotate) findViewById(R.id.imageRotate); mImageFlip = (ImageFlip) findViewById(R.id.imageFlip); mImageTinyPlanet = (ImageTinyPlanet) findViewById(R.id.imageTinyPlanet); mImageCrop.setAspectTextSize((int) getPixelsFromDip(18)); ImageCrop.setTouchTolerance((int) getPixelsFromDip(25)); mImageViews.add(mImageShow); mImageViews.add(mImageCurves); mImageViews.add(mImageBorders); mImageViews.add(mImageStraighten); mImageViews.add(mImageZoom); mImageViews.add(mImageCrop); mImageViews.add(mImageRotate); mImageViews.add(mImageFlip); mImageViews.add(mImageTinyPlanet); mListFx = findViewById(R.id.fxList); mListBorders = findViewById(R.id.bordersList); mListGeometry = findViewById(R.id.geometryList); mListFilterButtons = findViewById(R.id.filterButtonsList); mListColors = findViewById(R.id.colorsFxList); mListViews.add(mListFx); mListViews.add(mListBorders); mListViews.add(mListGeometry); mListViews.add(mListFilterButtons); mListViews.add(mListColors); mFxButton = (ImageButton) findViewById(R.id.fxButton); mBorderButton = (ImageButton) findViewById(R.id.borderButton); mGeometryButton = (ImageButton) findViewById(R.id.geometryButton); mColorsButton = (ImageButton) findViewById(R.id.colorsButton); mBottomPanelButtons.add(mFxButton); mBottomPanelButtons.add(mBorderButton); mBottomPanelButtons.add(mGeometryButton); mBottomPanelButtons.add(mColorsButton); mImageShow.setImageLoader(mImageLoader); mImageCurves.setImageLoader(mImageLoader); mImageCurves.setMaster(mImageShow); mImageBorders.setImageLoader(mImageLoader); mImageBorders.setMaster(mImageShow); mImageStraighten.setImageLoader(mImageLoader); mImageStraighten.setMaster(mImageShow); mImageZoom.setImageLoader(mImageLoader); mImageZoom.setMaster(mImageShow); mImageCrop.setImageLoader(mImageLoader); mImageCrop.setMaster(mImageShow); mImageRotate.setImageLoader(mImageLoader); mImageRotate.setMaster(mImageShow); mImageFlip.setImageLoader(mImageLoader); mImageFlip.setMaster(mImageShow); mImageTinyPlanet.setImageLoader(mImageLoader); mImageTinyPlanet.setMaster(mImageShow); mPanelController.setActivity(this); mPanelController.addImageView(findViewById(R.id.imageShow)); mPanelController.addImageView(findViewById(R.id.imageCurves)); mPanelController.addImageView(findViewById(R.id.imageBorder)); mPanelController.addImageView(findViewById(R.id.imageStraighten)); mPanelController.addImageView(findViewById(R.id.imageCrop)); mPanelController.addImageView(findViewById(R.id.imageRotate)); mPanelController.addImageView(findViewById(R.id.imageFlip)); mPanelController.addImageView(findViewById(R.id.imageZoom)); mPanelController.addImageView(findViewById(R.id.imageTinyPlanet)); mPanelController.addPanel(mFxButton, mListFx, 0); mPanelController.addPanel(mBorderButton, mListBorders, 1); mPanelController.addPanel(mGeometryButton, mListGeometry, 2); mPanelController.addComponent(mGeometryButton, findViewById(R.id.straightenButton)); mPanelController.addComponent(mGeometryButton, findViewById(R.id.cropButton)); mPanelController.addComponent(mGeometryButton, findViewById(R.id.rotateButton)); mPanelController.addComponent(mGeometryButton, findViewById(R.id.flipButton)); mPanelController.addPanel(mColorsButton, mListColors, 3); int[] recastIDs = { R.id.tinyplanetButton, R.id.vignetteButton, R.id.vibranceButton, R.id.contrastButton, R.id.saturationButton, R.id.bwfilterButton, R.id.wbalanceButton, R.id.hueButton, R.id.exposureButton, R.id.shadowRecoveryButton }; ImageFilter[] filters = { new ImageFilterTinyPlanet(), new ImageFilterVignette(), new ImageFilterVibrance(), new ImageFilterContrast(), new ImageFilterSaturated(), new ImageFilterBwFilter(), new ImageFilterWBalance(), new ImageFilterHue(), new ImageFilterExposure(), new ImageFilterShadows() }; for (int i = 0; i < filters.length; i++) { ImageSmallFilter fView = new ImageSmallFilter(this); View v = listColors.findViewById(recastIDs[i]); int pos = listColors.indexOfChild(v); listColors.removeView(v); filters[i].setParameter(filters[i].getPreviewParameter()); if (v instanceof ImageButtonTitle) filters[i].setName(((ImageButtonTitle) v).getText()); fView.setImageFilter(filters[i]); fView.setController(this); fView.setImageLoader(mImageLoader); fView.setId(recastIDs[i]); mPanelController.addComponent(mColorsButton, fView); listColors.addView(fView, pos); } int[] overlayIDs = {R.id.sharpenButton, R.id.curvesButtonRGB}; int[] overlayBitmaps = { R.drawable.filtershow_button_colors_sharpen, R.drawable.filtershow_button_colors_curve }; int[] overlayNames = {R.string.sharpness, R.string.curvesRGB}; for (int i = 0; i < overlayIDs.length; i++) { ImageWithIcon fView = new ImageWithIcon(this); View v = listColors.findViewById(overlayIDs[i]); int pos = listColors.indexOfChild(v); listColors.removeView(v); final int sid = overlayNames[i]; ImageFilterExposure efilter = new ImageFilterExposure() { { mName = getString(sid); } }; efilter.setParameter(-300); Bitmap bitmap = BitmapFactory.decodeResource(getResources(), overlayBitmaps[i]); fView.setIcon(bitmap); fView.setImageFilter(efilter); fView.setController(this); fView.setImageLoader(mImageLoader); fView.setId(overlayIDs[i]); mPanelController.addComponent(mColorsButton, fView); listColors.addView(fView, pos); } mPanelController.addView(findViewById(R.id.applyEffect)); mPanelController.addView(findViewById(R.id.pickCurvesChannel)); mPanelController.addView(findViewById(R.id.aspect)); findViewById(R.id.resetOperationsButton) .setOnClickListener(createOnClickResetOperationsButton()); ListView operationsList = (ListView) findViewById(R.id.operationsList); operationsList.setAdapter(mImageShow.getHistory()); operationsList.setOnItemClickListener(this); ListView imageStateList = (ListView) findViewById(R.id.imageStateList); imageStateList.setAdapter(mImageShow.getImageStateAdapter()); mImageLoader.setAdapter(mImageShow.getHistory()); fillListImages(listFilters); fillListBorders(listBorders); SeekBar seekBar = (SeekBar) findViewById(R.id.filterSeekBar); seekBar.setMax(SEEK_BAR_MAX); mImageShow.setSeekBar(seekBar); mImageZoom.setSeekBar(seekBar); mImageTinyPlanet.setSeekBar(seekBar); mPanelController.setRowPanel(findViewById(R.id.secondRowPanel)); mPanelController.setUtilityPanel( this, findViewById(R.id.filterButtonsList), findViewById(R.id.applyEffect), findViewById(R.id.aspect), findViewById(R.id.pickCurvesChannel)); mPanelController.setMasterImage(mImageShow); mPanelController.setCurrentPanel(mFxButton); Intent intent = getIntent(); if (intent.getBooleanExtra(LAUNCH_FULLSCREEN, false)) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); } if (intent.getData() != null) { startLoadBitmap(intent.getData()); } else { pickImage(); } String action = intent.getAction(); if (action.equalsIgnoreCase(CROP_ACTION)) { mPanelController.showComponent(findViewById(R.id.cropButton)); } else if (action.equalsIgnoreCase(TINY_PLANET_ACTION)) { mPanelController.showComponent(findViewById(R.id.tinyplanetButton)); } }
// called by onCreate; this is subclassed to overwrite WallpaperCropActivity protected void init() { setContentView(R.layout.wallpaper_picker); mCropView = (CropView) findViewById(R.id.cropView); mCropView.setVisibility(View.INVISIBLE); mWallpaperStrip = findViewById(R.id.wallpaper_strip); mCropView.setTouchCallback( new CropView.TouchCallback() { ViewPropertyAnimator mAnim; @Override public void onTouchDown() { if (mAnim != null) { mAnim.cancel(); } if (mWallpaperStrip.getAlpha() == 1f) { mIgnoreNextTap = true; } mAnim = mWallpaperStrip.animate(); mAnim .alpha(0f) .setDuration(150) .withEndAction( new Runnable() { public void run() { mWallpaperStrip.setVisibility(View.INVISIBLE); } }); mAnim.setInterpolator(new AccelerateInterpolator(0.75f)); mAnim.start(); } @Override public void onTouchUp() { mIgnoreNextTap = false; } @Override public void onTap() { boolean ignoreTap = mIgnoreNextTap; mIgnoreNextTap = false; if (!ignoreTap) { if (mAnim != null) { mAnim.cancel(); } mWallpaperStrip.setVisibility(View.VISIBLE); mAnim = mWallpaperStrip.animate(); mAnim.alpha(1f).setDuration(150).setInterpolator(new DecelerateInterpolator(0.75f)); mAnim.start(); } } }); mThumbnailOnClickListener = new OnClickListener() { public void onClick(View v) { if (mActionMode != null) { // When CAB is up, clicking toggles the item instead if (v.isLongClickable()) { mLongClickListener.onLongClick(v); } return; } mSetWallpaperButton.setEnabled(true); WallpaperTileInfo info = (WallpaperTileInfo) v.getTag(); if (info.isSelectable() && v.getVisibility() == View.VISIBLE) { selectTile(v); } info.onClick(WallpaperPickerActivity.this); } }; mLongClickListener = new View.OnLongClickListener() { // Called when the user long-clicks on someView public boolean onLongClick(View view) { CheckableFrameLayout c = (CheckableFrameLayout) view; c.toggle(); if (mActionMode != null) { mActionMode.invalidate(); } else { // Start the CAB using the ActionMode.Callback defined below mActionMode = startActionMode(mActionModeCallback); int childCount = mWallpapersView.getChildCount(); for (int i = 0; i < childCount; i++) { mWallpapersView.getChildAt(i).setSelected(false); } } return true; } }; // Populate the built-in wallpapers ArrayList<ResourceWallpaperInfo> wallpapers = findBundledWallpapers(); mWallpapersView = (LinearLayout) findViewById(R.id.wallpaper_list); BuiltInWallpapersAdapter ia = new BuiltInWallpapersAdapter(this, wallpapers); populateWallpapersFromAdapter(mWallpapersView, ia, false); // Populate the saved wallpapers mSavedImages = new SavedWallpaperImages(this); mSavedImages.loadThumbnailsAndImageIdList(); populateWallpapersFromAdapter(mWallpapersView, mSavedImages, true); // Populate the live wallpapers final LinearLayout liveWallpapersView = (LinearLayout) findViewById(R.id.live_wallpaper_list); final LiveWallpaperListAdapter a = new LiveWallpaperListAdapter(this); a.registerDataSetObserver( new DataSetObserver() { public void onChanged() { liveWallpapersView.removeAllViews(); populateWallpapersFromAdapter(liveWallpapersView, a, false); initializeScrollForRtl(); updateTileIndices(); } }); // Populate the third-party wallpaper pickers final LinearLayout thirdPartyWallpapersView = (LinearLayout) findViewById(R.id.third_party_wallpaper_list); final ThirdPartyWallpaperPickerListAdapter ta = new ThirdPartyWallpaperPickerListAdapter(this); populateWallpapersFromAdapter(thirdPartyWallpapersView, ta, false); // Add a tile for the Gallery LinearLayout masterWallpaperList = (LinearLayout) findViewById(R.id.master_wallpaper_list); FrameLayout pickImageTile = (FrameLayout) getLayoutInflater() .inflate(R.layout.wallpaper_picker_image_picker_item, masterWallpaperList, false); setWallpaperItemPaddingToZero(pickImageTile); masterWallpaperList.addView(pickImageTile, 0); // Make its background the last photo taken on external storage Bitmap lastPhoto = getThumbnailOfLastPhoto(); if (lastPhoto != null) { ImageView galleryThumbnailBg = (ImageView) pickImageTile.findViewById(R.id.wallpaper_image); galleryThumbnailBg.setImageBitmap(getThumbnailOfLastPhoto()); int colorOverlay = getResources().getColor(R.color.wallpaper_picker_translucent_gray); galleryThumbnailBg.setColorFilter(colorOverlay, PorterDuff.Mode.SRC_ATOP); } PickImageInfo pickImageInfo = new PickImageInfo(); pickImageTile.setTag(pickImageInfo); pickImageInfo.setView(pickImageTile); pickImageTile.setOnClickListener(mThumbnailOnClickListener); // Add a tile for the default wallpaper if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { DefaultWallpaperInfo defaultWallpaperInfo = getDefaultWallpaper(); if (defaultWallpaperInfo != null) { FrameLayout defaultWallpaperTile = (FrameLayout) createImageTileView( getLayoutInflater(), 0, null, mWallpapersView, defaultWallpaperInfo.mThumb); setWallpaperItemPaddingToZero(defaultWallpaperTile); defaultWallpaperTile.setTag(defaultWallpaperInfo); mWallpapersView.addView(defaultWallpaperTile, 0); defaultWallpaperTile.setOnClickListener(mThumbnailOnClickListener); defaultWallpaperInfo.setView(defaultWallpaperTile); } } // Select the first item; wait for a layout pass so that we initialize the dimensions of // cropView or the defaultWallpaperView first mCropView.addOnLayoutChangeListener( new OnLayoutChangeListener() { @Override public void onLayoutChange( View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { if ((right - left) > 0 && (bottom - top) > 0) { if (mSelectedIndex >= 0 && mSelectedIndex < mWallpapersView.getChildCount()) { mThumbnailOnClickListener.onClick(mWallpapersView.getChildAt(mSelectedIndex)); setSystemWallpaperVisiblity(false); } v.removeOnLayoutChangeListener(this); } } }); updateTileIndices(); // Update the scroll for RTL initializeScrollForRtl(); // Create smooth layout transitions for when items are deleted final LayoutTransition transitioner = new LayoutTransition(); transitioner.setDuration(200); transitioner.setStartDelay(LayoutTransition.CHANGE_DISAPPEARING, 0); transitioner.setAnimator(LayoutTransition.DISAPPEARING, null); mWallpapersView.setLayoutTransition(transitioner); // Action bar // Show the custom action bar view final ActionBar actionBar = getActionBar(); actionBar.setCustomView(R.layout.actionbar_set_wallpaper); actionBar .getCustomView() .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (mSelectedTile != null) { WallpaperTileInfo info = (WallpaperTileInfo) mSelectedTile.getTag(); info.onSave(WallpaperPickerActivity.this); } else { // no tile was selected, so we just finish the activity and go back setResult(Activity.RESULT_OK); finish(); } } }); mSetWallpaperButton = findViewById(R.id.set_wallpaper_button); // CAB for deleting items mActionModeCallback = new ActionMode.Callback() { // Called when the action mode is created; startActionMode() was called @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { // Inflate a menu resource providing context menu items MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.cab_delete_wallpapers, menu); return true; } private int numCheckedItems() { int childCount = mWallpapersView.getChildCount(); int numCheckedItems = 0; for (int i = 0; i < childCount; i++) { CheckableFrameLayout c = (CheckableFrameLayout) mWallpapersView.getChildAt(i); if (c.isChecked()) { numCheckedItems++; } } return numCheckedItems; } // Called each time the action mode is shown. Always called after onCreateActionMode, // but may be called multiple times if the mode is invalidated. @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { int numCheckedItems = numCheckedItems(); if (numCheckedItems == 0) { mode.finish(); return true; } else { mode.setTitle( getResources() .getQuantityString( R.plurals.number_of_items_selected, numCheckedItems, numCheckedItems)); return true; } } // Called when the user selects a contextual menu item @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { int itemId = item.getItemId(); if (itemId == R.id.menu_delete) { int childCount = mWallpapersView.getChildCount(); ArrayList<View> viewsToRemove = new ArrayList<View>(); boolean selectedTileRemoved = false; for (int i = 0; i < childCount; i++) { CheckableFrameLayout c = (CheckableFrameLayout) mWallpapersView.getChildAt(i); if (c.isChecked()) { WallpaperTileInfo info = (WallpaperTileInfo) c.getTag(); info.onDelete(WallpaperPickerActivity.this); viewsToRemove.add(c); if (i == mSelectedIndex) { selectedTileRemoved = true; } } } for (View v : viewsToRemove) { mWallpapersView.removeView(v); } if (selectedTileRemoved) { mSelectedIndex = -1; mSelectedTile = null; setSystemWallpaperVisiblity(true); } updateTileIndices(); mode.finish(); // Action picked, so close the CAB return true; } else { return false; } } // Called when the user exits the action mode @Override public void onDestroyActionMode(ActionMode mode) { int childCount = mWallpapersView.getChildCount(); for (int i = 0; i < childCount; i++) { CheckableFrameLayout c = (CheckableFrameLayout) mWallpapersView.getChildAt(i); c.setChecked(false); } if (mSelectedTile != null) { mSelectedTile.setSelected(true); } mActionMode = null; } }; }