List of usage examples for android.graphics.drawable AnimationDrawable AnimationDrawable
public AnimationDrawable()
From source file:com.cnm.cnmrc.fragment.rc.RcBase.java
/** * Loading TapPressAnimation <br>/*w w w . ja va 2s. c o m*/ */ protected void startLoadingAni(ImageButton view, final ImageView animView) { if (view != null) { view.post(new Runnable() { @Override public void run() { try { mTapPressAnimation = new AnimationDrawable(); mTapPressAnimation.addFrame(getResources().getDrawable(R.drawable.tappress01), 60); mTapPressAnimation.addFrame(getResources().getDrawable(R.drawable.tappress02), 60); mTapPressAnimation.addFrame(getResources().getDrawable(R.drawable.tappress03), 60); mTapPressAnimation.addFrame(getResources().getDrawable(R.drawable.tappress04), 60); mTapPressAnimation.setOneShot(true); animView.setImageDrawable(mTapPressAnimation); // API 2.3.4? ?... ??? // animView.setBackgroundResource(R.drawable.anim_tappress); // mTapPressAnimation = (AnimationDrawable) // animView.getBackground(); mTapPressDuration = 0; for (int i = 0; i < mTapPressAnimation.getNumberOfFrames(); i++) { mTapPressDuration += mTapPressAnimation.getDuration(i); } animView.setVisibility(View.VISIBLE); // Start the animation (looped playback by default). mTapPressAnimation.start(); mHandler.postDelayed(new Runnable() { public void run() { mTapPressAnimation.stop(); mTapPressAnimation = null; animView.setBackgroundResource(0); animView.setVisibility(View.INVISIBLE); oneClickTapPress = true; } }, mTapPressDuration); } catch (Exception e) { e.getStackTrace(); } } }); } //view.post(new Starter()); }
From source file:com.adkdevelopment.simpleflashlightadfree.ui.EmergencyFragment.java
/** * Starts emergency sound from assets//from w ww .j av a 2s . co m */ public void emergencySignal() { try { if (mMediaPlayer != null && mMediaPlayer.isPlaying() && status == FlashlightService.STATUS_OFF) { mMediaPlayer.stop(); mMediaPlayer.reset(); mMediaPlayer.release(); mMediaPlayer = null; mLinearLayout.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.colorBackground)); } else if (status == FlashlightService.STATUS_BLINK) { final AnimationDrawable drawable = new AnimationDrawable(); final Handler handler = new Handler(); drawable.addFrame(new ColorDrawable(Color.RED), 400); drawable.addFrame(new ColorDrawable(Color.BLUE), 400); drawable.setOneShot(false); mLinearLayout.setBackground(drawable); handler.postDelayed(new Runnable() { @Override public void run() { drawable.start(); } }, 100); mMediaPlayer = new MediaPlayer(); AssetFileDescriptor descriptor = getActivity().getAssets().openFd("sews.mp3"); mMediaPlayer.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength()); descriptor.close(); mMediaPlayer.prepare(); mMediaPlayer.setVolume(1f, 1f); mMediaPlayer.setLooping(true); mMediaPlayer.start(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.cnm.cnmrc.fragment.RcChannelVolume.java
/** * Loading TapPressAnimation <br>//from w w w .j a va2 s .c o m */ private void startLoadingAni(ImageButton view, final ImageView animView) { if (view != null) { view.post(new Runnable() { @Override public void run() { try { mTapPressAnimation = new AnimationDrawable(); mTapPressAnimation.addFrame(getResources().getDrawable(R.drawable.tappress01), 60); mTapPressAnimation.addFrame(getResources().getDrawable(R.drawable.tappress02), 60); mTapPressAnimation.addFrame(getResources().getDrawable(R.drawable.tappress03), 60); mTapPressAnimation.addFrame(getResources().getDrawable(R.drawable.tappress04), 60); mTapPressAnimation.setOneShot(true); animView.setImageDrawable(mTapPressAnimation); // API 2.3.4? ?... ??? // animView.setBackgroundResource(R.drawable.anim_tappress); // mTapPressAnimation = (AnimationDrawable) // animView.getBackground(); mTapPressDuration = 0; for (int i = 0; i < mTapPressAnimation.getNumberOfFrames(); i++) { mTapPressDuration += mTapPressAnimation.getDuration(i); } animView.setVisibility(View.VISIBLE); // Start the animation (looped playback by default). mTapPressAnimation.start(); mHandler.postDelayed(new Runnable() { public void run() { mTapPressAnimation.stop(); mTapPressAnimation = null; animView.setBackgroundResource(0); animView.setVisibility(View.INVISIBLE); oneClickTapPress = true; } }, mTapPressDuration); } catch (Exception e) { e.getStackTrace(); } } }); } //view.post(new Starter()); }
From source file:com.google.android.apps.santatracker.games.matching.MemoryMatchFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_memory_match, container, false); rootView.setKeepScreenOn(true);//from w w w. j a va2 s. com // Below ICS, display a special, simplified background for the entire fragment if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { rootView.findViewById(R.id.match_score_layout) .setBackgroundResource(R.drawable.score_background_gingerbread); } // Initialise the sound pool and all sound effects mSoundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0); mSoundDoorOpen = mSoundPool.load(getActivity(), R.raw.mmg_open_door_3, 1); mSoundDoorClose = mSoundPool.load(getActivity(), R.raw.mmg_close_door, 1); mSoundMatchWrong = mSoundPool.load(getActivity(), R.raw.mmg_wrong, 1); mSoundMatchRight = mSoundPool.load(getActivity(), R.raw.mmg_right, 1); mSoundGameOver = mSoundPool.load(getActivity(), R.raw.gameover, 1); mSoundBeep = mSoundPool.load(getActivity(), R.raw.mmg_open_door_2, 1); // Set up all animations. loadAnimations(); // G+ sign-in views mViewGPlusSignIn = (ImageView) rootView.findViewById(R.id.gplus_button); mViewGPlusSignIn.setOnClickListener(this); mLayoutGPlus = rootView.findViewById(R.id.play_again_gplus); mLayoutGPlus.setVisibility(View.GONE); // 'Play again' screen views mTextPlayAgainScore = (TextView) rootView.findViewById(R.id.play_again_score); mTextPlayAgainScore.setText(String.valueOf(mMatchScore)); mTextPlayAgainLevel = (TextView) rootView.findViewById(R.id.play_again_level); mTextPlayAgainLevel.setText(String.valueOf(mLevelNumber)); mViewPlayAgainBackground = rootView.findViewById(R.id.play_again_bkgrd); mViewPlayAgainMain = rootView.findViewById(R.id.play_again_main); mPlayAgainBtn = (Button) rootView.findViewById(R.id.play_again_btn); mPlayAgainBtn.setOnClickListener(this); // Level, countdown and score views at the bottom of the screen mTimerTextView = (TextView) rootView.findViewById(R.id.match_timer); mLevelNumberText = (LevelTextView) rootView.findViewById(R.id.card_end_level_number); mLevelNumberText.setVisibility(View.GONE); mScoreText = (TextView) rootView.findViewById(R.id.match_score); mScoreText.setText(String.valueOf(mMatchScore)); // End of level animated circle mEndLevelCircle = (CircleView) rootView.findViewById(R.id.card_end_level_circle); mEndLevelCircle.setVisibility(View.GONE); // The snowman that is animated as a bonus when the player is particularly awesome mViewBonusSnowman = rootView.findViewById(R.id.match_snowman); // 'Pause' screen views mButtonMenu = (ImageButton) rootView.findViewById(R.id.main_menu_button); mButtonMenu.setOnClickListener(this); mButtonMenu.setVisibility(View.GONE); mButtonPlay = (ImageView) rootView.findViewById(R.id.match_play_button); mButtonPlay.setOnClickListener(this); mButtonPlay.setVisibility(View.GONE); mButtonPause = (ImageView) rootView.findViewById(R.id.match_pause_button); mButtonPause.setOnClickListener(this); mButtonPause.setVisibility(View.VISIBLE); mViewPauseOverlay = rootView.findViewById(R.id.match_pause_overlay); mViewPauseOverlay.setVisibility(View.GONE); mButtonBigPlay = (ImageButton) rootView.findViewById(R.id.match_big_play_button); mButtonBigPlay.setOnClickListener(this); mButtonCancelBar = (ImageButton) rootView.findViewById(R.id.match_cancel_bar); mButtonCancelBar.setOnClickListener(this); mButtonCancelBar.setVisibility(View.GONE); // Playing cards (doors) mViewCard[0] = rootView.findViewById(R.id.card_position_1); mViewCard[1] = rootView.findViewById(R.id.card_position_2); mViewCard[2] = rootView.findViewById(R.id.card_position_3); mViewCard[3] = rootView.findViewById(R.id.card_position_4); mViewCard[4] = rootView.findViewById(R.id.card_position_5); mViewCard[5] = rootView.findViewById(R.id.card_position_6); mViewCard[6] = rootView.findViewById(R.id.card_position_7); mViewCard[7] = rootView.findViewById(R.id.card_position_8); mViewCard[8] = rootView.findViewById(R.id.card_position_9); mViewCard[9] = rootView.findViewById(R.id.card_position_10); mViewCard[10] = rootView.findViewById(R.id.card_position_11); mViewCard[11] = rootView.findViewById(R.id.card_position_12); // Display the instructions if they haven't been seen by the player yet. mPreferences = getActivity().getSharedPreferences(MatchingGameConstants.PREFERENCES_FILENAME, Context.MODE_PRIVATE); if (!mPreferences.getBoolean(MatchingGameConstants.MATCH_INSTRUCTIONS_VIEWED, false)) { // Instructions haven't been viewed yet. Construct an AnimationDrawable with instructions. mInstructionDrawable = new AnimationDrawable(); mInstructionDrawable.addFrame(getResources().getDrawable(R.drawable.instructions_touch_1), 300); mInstructionDrawable.addFrame(getResources().getDrawable(R.drawable.instructions_touch_2), 300); mInstructionDrawable.setOneShot(false); mViewInstructions = (ImageView) rootView.findViewById(R.id.instructions); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { mViewInstructions.setImageResource(R.drawable.instructions_touch_1); } else { mViewInstructions.setImageDrawable(mInstructionDrawable); mInstructionDrawable.start(); } // Set a timer to hide the instructions after 2 seconds mViewInstructions.postDelayed(new StartGameDelay(), 2000); } else { //Instructions have already been viewed. Start the first level. setUpLevel(); } return rootView; }
From source file:com.google.android.apps.santatracker.games.gumball.TiltGameFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mRootView = inflater.inflate(R.layout.fragment_gumball, container, false); mRootView.setKeepScreenOn(true);//w ww. j a v a 2 s . c om // Use a lower resolution background image to conserve memory below ICS if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { View matchScoreLayout = mRootView.findViewById(R.id.tilt_score_layout); matchScoreLayout.setBackgroundResource(R.drawable.score_background_gingerbread); } mViewPlayAgainScore = (TextView) mRootView.findViewById(R.id.play_again_score); mViewPlayAgainScore.setText(String.valueOf(mMatchScore)); mViewPlayAgainLevel = (TextView) mRootView.findViewById(R.id.play_again_level); mViewPlayAgainLevel.setText(String.valueOf(mCurrentLevelNum)); mViewPlayAgainBackground = mRootView.findViewById(R.id.play_again_bkgrd); mViewPlayAgainMain = mRootView.findViewById(R.id.play_again_main); mViewPlayAgainButton = (Button) mRootView.findViewById(R.id.play_again_btn); mViewPlayAgainButton.setOnClickListener(this); mViewGPlusSignIn = (ImageView) mRootView.findViewById(R.id.gplus_button); mViewGPlusSignIn.setOnClickListener(this); mViewGPlusLayout = mRootView.findViewById(R.id.play_again_gplus); mViewGPlusLayout.setVisibility(View.GONE); // Initialise all animations // Construct an animation to blink the timer indefinitely mAnimationTimerAlpha = new AlphaAnimation(0.0f, 1.0f); mAnimationTimerAlpha.setDuration(1000); mAnimationTimerAlpha.setRepeatMode(Animation.REVERSE); mAnimationTimerAlpha.setRepeatCount(Animation.INFINITE); // Load all other animations mAnimationPlayAgainBackground = AnimationUtils.loadAnimation(getActivity(), R.anim.play_again_bkgrd_anim); mAnimationPlayAgainBackground.setFillAfter(true); mAnimationPlayAgainBackground.setAnimationListener(this); mAnimationPlayAgainMain = AnimationUtils.loadAnimation(getActivity(), R.anim.play_again_main_anim); mAnimationPlayAgainMain.setFillAfter(true); mAnimationPlayAgainMain.setAnimationListener(this); mAnimationScaleLevelDown = AnimationUtils.loadAnimation(getActivity(), R.anim.scale_level_anim_down); mAnimationScaleLevelDown.setAnimationListener(this); mAnimationLevelFadeOut = AnimationUtils.loadAnimation(getActivity(), R.anim.level_fade_out_anim); mAnimationLevelFadeOut.setAnimationListener(this); mAnimationLevelScaleUp = AnimationUtils.loadAnimation(getActivity(), R.anim.scale_up_level_anim); mAnimationLevelScaleUp.setAnimationListener(this); mViewMainMenuButton = (ImageButton) mRootView.findViewById(R.id.main_menu_button); mViewMainMenuButton.setVisibility(View.GONE); mViewMainMenuButton.setOnClickListener(this); mGameOutlet = mRootView.findViewById(R.id.tiltGameOutlet); mOutletOffset = getResources().getInteger(R.integer.outlet_offset); mViewIndicators[0] = (ImageView) mRootView.findViewById(R.id.indicator1); mViewIndicators[1] = (ImageView) mRootView.findViewById(R.id.indicator2); mViewIndicators[2] = (ImageView) mRootView.findViewById(R.id.indicator3); mViewIndicators[3] = (ImageView) mRootView.findViewById(R.id.indicator4); mViewIndicators[4] = (ImageView) mRootView.findViewById(R.id.indicator5); mViewIndicators[5] = (ImageView) mRootView.findViewById(R.id.indicator6); mViewCountdown = (TextView) mRootView.findViewById(R.id.tiltTimer); mLevelNumberText = (LevelTextView) mRootView.findViewById(R.id.tilt_end_level_number); mLevelNumberText.setVisibility(View.GONE); mEndLevelCircle = (CircleView) mRootView.findViewById(R.id.tilt_end_level_circle); mEndLevelCircle.setVisibility(View.GONE); mViewPlayButton = (ImageView) mRootView.findViewById(R.id.tilt_play_button); mViewPlayButton.setOnClickListener(this); mViewPlayButton.setVisibility(View.GONE); mViewPauseButton = (ImageView) mRootView.findViewById(R.id.tilt_pause_button); mViewPauseButton.setOnClickListener(this); mViewPauseButton.setVisibility(View.VISIBLE); mViewMatchPauseOverlay = mRootView.findViewById(R.id.tilt_pause_overlay); mViewMatchPauseOverlay.setVisibility(View.GONE); mViewBigPlayButton = (ImageButton) mRootView.findViewById(R.id.tilt_big_play_button); mViewBigPlayButton.setOnClickListener(this); mViewCancelBar = (ImageView) mRootView.findViewById(R.id.tilt_cancel_bar); mViewCancelBar.setOnClickListener(this); mViewCancelBar.setVisibility(View.GONE); mViewScore = (TextView) mRootView.findViewById(R.id.tilt_score); mViewScore.setText(String.valueOf(mMatchScore)); mGameView = (TiltGameView) mRootView.findViewById(R.id.tiltGameView); // Create the Box2D physics world. mWorld = new PhysicsWorld(); Vec2 gravity = new Vec2(0.0f, 0.0f); mWorld.create(gravity); mGameView.setModel(mWorld); mWorld.getWorld().setContactListener(this); mGumballQueue = new LinkedList<>(); // Initialise the sound pool and audio playback mSoundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0); mSoundBounceSmall = mSoundPool.load(getActivity(), R.raw.gbg_ball_bounce_1, 1); mSoundBounceMed = mSoundPool.load(getActivity(), R.raw.gbg_ball_bounce_2, 1); mSoundBounceLarge = mSoundPool.load(getActivity(), R.raw.gbg_ball_bounce_3, 1); mSoundBallInMachine = mSoundPool.load(getActivity(), R.raw.gbg_ball_into_machine, 1); mSoundBallFail = mSoundPool.load(getActivity(), R.raw.gbg_ball_fall_out, 1); mSoundBallDrop = mSoundPool.load(getActivity(), R.raw.gbg_new_ball_bounce_drop, 1); mSoundGameOver = mSoundPool.load(getActivity(), R.raw.gameover, 1); // Display the instructions if they haven't been seen before mSharedPreferences = getActivity().getSharedPreferences(MatchingGameConstants.PREFERENCES_FILENAME, Context.MODE_PRIVATE); if (!mSharedPreferences.getBoolean(MatchingGameConstants.GUMBALL_INSTRUCTIONS_VIEWED, false)) { mDrawableTransition = new AnimationDrawable(); mDrawableTransition.addFrame(getResources().getDrawable(R.drawable.instructions_shake_1), 300); mDrawableTransition.addFrame(getResources().getDrawable(R.drawable.instructions_shake_2), 300); mDrawableTransition.addFrame(getResources().getDrawable(R.drawable.instructions_shake_3), 300); mDrawableTransition.setOneShot(false); mViewInstructions = (ImageView) mRootView.findViewById(R.id.instructions); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { mViewInstructions.setImageResource(R.drawable.instructions_shake_1); } else { mViewInstructions.setImageDrawable(mDrawableTransition); mViewInstructions.post(new Runnable() { public void run() { mDrawableTransition.start(); } }); } // Hide the instructions after 2 seconds mViewInstructions.postDelayed(new HideInstructionsRunnable(), 2200); } return mRootView; }
From source file:com.actionbarsherlock.internal.widget.IcsProgressBar.java
/** * Convert a AnimationDrawable for use as a barberpole animation. * Each frame of the animation is wrapped in a ClipDrawable and * given a tiling BitmapShader.//from w ww.jav a2 s .c o m */ private Drawable tileifyIndeterminate(Drawable drawable) { if (drawable instanceof AnimationDrawable) { AnimationDrawable background = (AnimationDrawable) drawable; final int N = background.getNumberOfFrames(); AnimationDrawable newBg = new AnimationDrawable(); newBg.setOneShot(background.isOneShot()); for (int i = 0; i < N; i++) { Drawable frame = tileify(background.getFrame(i), true); frame.setLevel(10000); newBg.addFrame(frame, background.getDuration(i)); } newBg.setLevel(10000); drawable = newBg; } return drawable; }
From source file:com.example.search.car.pools.welcome.java
@Override public void onClick(View v) { // TODO Auto-generated method stub Fragment fragment = null;//ww w .j a va2 s . c om if ((v.equals(l_1) || (v.equals(sp_city)))) { String[] city = { "Delhi/NCR", "Bengaluru", "Kolkata", "Mumbai", "Pune", "Ahmedabad" }; dialog("City", city, sp_city); } else if ((v.equals(l_2) || (v.equals(sp_category)))) { String[] category = { "All", "Carpool", "Cab", "Rideshare" }; dialog("Category", category, sp_category); } else if ((v.equals(l_3) || (v.equals(sp_search_for)))) { String[] search_for = { "Seeker", "Provider", "Both" }; dialog(" Search For", search_for, sp_search_for); } else if (v.equals(close)) { promptsView.dismiss(); } else if (v.equals(rlCities)) { layout = "Cities"; fragment = new Cities(); frag_tag = "Cities"; set_fragment(fragment); mDrawerLayout.closeDrawer(mDrawerList); // getActionBar().setTitle("Cities"); svg_cities = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.city1); iv_cities.setImageDrawable(svg_cities.createPictureDrawable()); rlCities.setBackgroundColor(Color.parseColor("#00ca98")); l_cities.setBackground(getResources().getDrawable(R.drawable.white_circle_side_menu)); svg_dashboard = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.dashboard); iv_dashboard.setImageDrawable(svg_dashboard.createPictureDrawable()); rlDashboard.setBackgroundColor(Color.parseColor("#2C3E50")); l_dashboard.setBackground(getResources().getDrawable(R.drawable.search_blue)); svg_search = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.search); iv_search.setImageDrawable(svg_search.createPictureDrawable()); rlSearch.setBackgroundColor(Color.parseColor("#2C3E50")); l_search.setBackground(getResources().getDrawable(R.drawable.search_blue)); } else if (v.equals(rlDashboard)) { if (task.getString("user_id", null) != null) { // layout = "Dashboard"; // fragment = new dashboard(); // frag_tag = "Dashboard"; // // getActionBar().setTitle("My Profile"); // set_fragment(fragment); // mDrawerLayout.closeDrawer(mDrawerList); // svg_dashboard = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.dashboard1); // iv_dashboard.setImageDrawable(svg_dashboard.createPictureDrawable()); // rlDashboard.setBackgroundColor(Color.parseColor("#00ca98")); // l_dashboard.setBackground(getResources().getDrawable(R.drawable.white_circle_side_menu)); // // svg_cities = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.city); // iv_cities.setImageDrawable(svg_cities.createPictureDrawable()); // rlCities.setBackgroundColor(Color.parseColor("#2C3E50")); // l_cities.setBackground(getResources().getDrawable(R.drawable.search_blue)); // svg_search = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.search); // iv_search.setImageDrawable(svg_search.createPictureDrawable()); // rlSearch.setBackgroundColor(Color.parseColor("#2C3E50")); // l_search.setBackground(getResources().getDrawable(R.drawable.search_blue)); Intent i = new Intent(welcome.this, dashboard_main.class); i.putExtra("edit", "1"); startActivity(i); mDrawerLayout.closeDrawer(mDrawerList); } else { Toast.makeText(welcome.this, "Please Login First", Toast.LENGTH_SHORT).show(); mDrawerLayout.closeDrawer(mDrawerList); } } else if (v.equals(rlSearch)) { layout = "Search"; frag_tag = "Search"; fragment = new Search(); set_fragment(fragment); mDrawerLayout.closeDrawer(mDrawerList); // getActionBar().setTitle("Search"); svg_search = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.search1); iv_search.setImageDrawable(svg_search.createPictureDrawable()); rlSearch.setBackgroundColor(Color.parseColor("#00ca98")); l_search.setBackground(getResources().getDrawable(R.drawable.white_circle_side_menu)); svg_dashboard = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.dashboard); iv_dashboard.setImageDrawable(svg_dashboard.createPictureDrawable()); rlDashboard.setBackgroundColor(Color.parseColor("#2C3E50")); l_dashboard.setBackground(getResources().getDrawable(R.drawable.search_blue)); svg_cities = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.city); iv_cities.setImageDrawable(svg_cities.createPictureDrawable()); rlCities.setBackgroundColor(Color.parseColor("#2C3E50")); l_cities.setBackground(getResources().getDrawable(R.drawable.search_blue)); } else if (v.equals(rlProfile_login) || v.equals(profile_login)) { if (task.getString("user_id", null) == null) { Intent i = new Intent(getBaseContext(), user_login.class); i.putExtra("frag_id", frag_id); startActivity(i); } mDrawerLayout.closeDrawer(mDrawerList); } // else if (v.equals(rlEditProfile)) { // if (task.getString("user_id", null) != null) { // Intent i = new Intent(welcome.this, dashboard_main.class); // i.putExtra("edit", "3"); // startActivity(i); // } else { // Toast.makeText(welcome.this, "Please Login First", Toast.LENGTH_SHORT).show(); // } // mDrawerLayout.closeDrawer(mDrawerList); // } else if (v.equals(login) || v.equals(rlLogin)) { if (task.getString("user_id", null) != null && login.getText().toString().contentEquals("Logout")) { SharedPreferences.Editor editor = getSharedPreferences("user", MODE_PRIVATE).edit(); editor.clear(); editor.commit(); login.setText("Login"); rlDashboard.setVisibility(View.GONE); // rlEditProfile.setVisibility(View.GONE); if (layout.contentEquals("Dashboard") || frag_tag.contentEquals("Dashboard")) { // highlight search menu on slider during on resume // change fragment to search FragmentManager fm = getFragmentManager(); FragmentTransaction fragmentTransaction = fm.beginTransaction(); fragmentTransaction.replace(R.id.content_frame, new Search()); fragmentTransaction.commit(); svg_search = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.search1); iv_search.setImageDrawable(svg_search.createPictureDrawable()); rlSearch.setBackgroundColor(Color.parseColor("#00ca98")); l_search.setBackground(getResources().getDrawable(R.drawable.white_circle_side_menu)); } iv_login.setImageDrawable(svg_login.createPictureDrawable()); rlProfile.setVisibility(View.GONE); rlProfile_login.setVisibility(View.VISIBLE); if (frag_id == 6) { Intent i_user = new Intent(getBaseContext(), user_login.class); i_user.putExtra("frag_id", frag_id); startActivity(i_user); } } else { Intent i = new Intent(getBaseContext(), user_login.class); i.putExtra("frag_id", frag_id); startActivity(i); } mDrawerLayout.closeDrawer(mDrawerList); } else if (v.equals(b_search)) { if (sp_city.getText().toString().toUpperCase().equals("SELECT CITY")) { Toast.makeText(welcome.this, "First Select the City", Toast.LENGTH_LONG).show(); } else { Intent i = new Intent(welcome.this, search_result.class); i.putExtra("city", sp_city.getText().toString()); i.putExtra("category", sp_category.getText().toString()); i.putExtra("search_for", sp_search_for.getText().toString()); i.putExtra("from", et_from.getText().toString()); i.putExtra("to", et_to.getText().toString()); i.putExtra("frag_id", 1); i.putExtra("company_id", 0); startActivity(i); promptsView.dismiss(); } } else if (v.equals(l_nav_search) || v.equals(ib_search)) { final int DELAY = 200; // ColorDrawable f = new // ColorDrawable(Color.parseColor("#0087ca")); // ColorDrawable f1 = new // ColorDrawable(Color.parseColor("#3398ca")); AnimationDrawable a = new AnimationDrawable(); a.addFrame(d1, DELAY); a.addFrame(d2, DELAY); a.setOneShot(true); l_nav_search.setBackground(a); a.start(); showSearchDialog(); } else if (v.equals(l_handle) || v.equals(ib_handle)) { final int DELAY = 200; // ColorDrawable f = new // ColorDrawable(Color.parseColor("#0087ca")); // ColorDrawable f1 = new // ColorDrawable(Color.parseColor("#3398ca")); AnimationDrawable a = new AnimationDrawable(); a.addFrame(d1, DELAY); a.addFrame(d2, DELAY); a.setOneShot(true); l_handle.setBackground(a); a.start(); if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) { mDrawerLayout.closeDrawer(mDrawerList); } else { mDrawerLayout.openDrawer(mDrawerList); } } else if (v.equals(l_menu) || v.equals(ib_menu)) { final int DELAY = 200; // for light background // ColorDrawable f = new // ColorDrawable(Color.parseColor("#0087ca")); // ColorDrawable f1 = new // ColorDrawable(Color.parseColor("#3398ca")); AnimationDrawable a = new AnimationDrawable(); a.addFrame(d1, DELAY); a.addFrame(d2, DELAY); a.setOneShot(true); l_menu.setBackground(a); a.start(); final PopupMenu popup = new PopupMenu(welcome.this, v); popup.getMenuInflater().inflate(R.menu.main, popup.getMenu()); bedMenuItem = popup.getMenu().findItem(R.id.menu_login); final SharedPreferences task = getSharedPreferences("user", MODE_PRIVATE); popup.getMenu().findItem(R.id.menu_add_new_list).setVisible(!(task.getString("user_id", null) == null)); popup.getMenu().findItem(R.id.menu_dashboard).setVisible(!(task.getString("user_id", null) == null)); if (task.getString("user_id", null) != null) { bedMenuItem.setTitle("Logout"); login.setText("Logout"); iv_login.setImageDrawable(svg_logout.createPictureDrawable()); rlProfile.setVisibility(View.VISIBLE); rlProfile_login.setVisibility(View.GONE); rlDashboard.setVisibility(View.VISIBLE); // rlEditProfile.setVisibility(View.VISIBLE); set_data(); } else { bedMenuItem.setTitle("Login/Register"); login.setText("Login"); iv_login.setImageDrawable(svg_login.createPictureDrawable()); rlDashboard.setVisibility(View.GONE); // rlEditProfile.setVisibility(View.GONE); rlProfile.setVisibility(View.GONE); rlProfile_login.setVisibility(View.VISIBLE); } if (task.getString("user_id", null) != null) { popup.getMenu().findItem(R.id.menu_login).setTitle("Logout"); } else { popup.getMenu().findItem(R.id.menu_login).setTitle("Login/Register"); } popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { // TODO Auto-generated method stub int id = item.getItemId(); Intent i; switch (id) { case R.id.menu_add_new_list: if (task.getString("user_id", null) != null) { i = new Intent(welcome.this, create_activity.class); startActivity(i); } else { Toast.makeText(welcome.this, "Login first", Toast.LENGTH_SHORT).show(); } return true; case R.id.menu_dashboard: if (task.getString("user_id", null) != null) { i = new Intent(welcome.this, dashboard_main.class); i.putExtra("edit", "12344"); startActivity(i); } else { Toast.makeText(welcome.this, "Please Login first", Toast.LENGTH_LONG).show(); } return true; case R.id.menu_login: if (bedMenuItem.getTitle().equals("Logout")) { SharedPreferences.Editor editor = getSharedPreferences("user", MODE_PRIVATE).edit(); editor.clear(); editor.commit(); // bedMenuItem.setTitle("Login/Register"); login.setText("Login"); rlDashboard.setVisibility(View.GONE); // rlEditProfile.setVisibility(View.GONE); if (layout.contentEquals("Dashboard") || frag_tag.contentEquals("Dashboard")) { // highlight search menu on slider during on // resume // change fragment to search FragmentManager fm = getFragmentManager(); FragmentTransaction fragmentTransaction = fm.beginTransaction(); fragmentTransaction.replace(R.id.content_frame, new Search()); fragmentTransaction.commit(); SVG svg_search = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.search1); iv_search.setImageDrawable(svg_search.createPictureDrawable()); rlSearch.setBackgroundColor(Color.parseColor("#00ca98")); l_search.setBackground( getResources().getDrawable(R.drawable.white_circle_side_menu)); } iv_login.setImageDrawable(svg_login.createPictureDrawable()); rlProfile.setVisibility(View.GONE); rlProfile_login.setVisibility(View.VISIBLE); if (frag_id == 6) { Intent i_user = new Intent(getBaseContext(), user_login.class); i_user.putExtra("frag_id", frag_id); startActivity(i_user); } } else { i = new Intent(getBaseContext(), user_login.class); i.putExtra("frag_id", frag_id); startActivity(i); } return true; } return false; } }); popup.show(); // } else { // openOptionsMenu(); // } } }