error in java android programming - java

I'm trying to make a property animation on ImageButton, a button will start the animation when clicked on, but in the private static class ImageButtonAnimatorHelper method, it's showing an error.
public class MainActivity extends Activity {
// ImageButton jackfruit = (ImageButton) findViewById(R.id.btnjackfruit);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button but = (Button) findViewById(R.id.btn);
but.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
ball();
}
public void ball() {
ImageButton ball = (ImageButton) findViewById(R.id.btnball);
ball.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(final View v) {
// ImageButton b = (ImageButton) findViewById(R.id.btnball);
ImageView banan = (ImageView) findViewById(R.id.banana);
banan.setVisibility(View.VISIBLE);
} // onClick
}); // setOnClickListener
ObjectAnimator horizontalAnimator = ObjectAnimator.ofInt(
new ImageButtonAnimatorHelper(ball), "marginLeft", 0, 600);
horizontalAnimator.setDuration(2000);
horizontalAnimator.setRepeatCount(ValueAnimator.INFINITE);
horizontalAnimator.setRepeatMode(ValueAnimator.REVERSE);
horizontalAnimator.setInterpolator(new LinearInterpolator());
horizontalAnimator.start();
} // onCreate
private static class ImageButtonAnimatorHelper {
ImageButton ballButton;
public ImageButtonAnimatorHelper(ImageButton imagebutton) {
ballButton = imagebutton;
}
public void setMarginLeft(int margin) {
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) ballButton
.getLayoutParams();
params.leftMargin = margin;
ballButton.setLayoutParams(params);
} // setMarginLeft
} // ImageButtonAnimatorHelper
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
I'm confused with when to use private/public/abstract class..

Related

How to access array of drawables from a method

I have researched similar problems but none is a fit for this problem. Am trying to access the arrays of drawables from the method name called nextQuestion(), but i keep getting the error cannot resolve symbol 'ballArray' any help please. I just feel that this should work but don't know why. Here is my code.
public class MainActivity extends AppCompatActivity {
ImageView mBallDisplay;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int quote;
mBallDisplay = (ImageView) findViewById(R.id.image_eightBall);
Button nextbutton = (Button) findViewById(R.id.nextbutton);
Button prevbutton = (Button) findViewById(R.id.prevbutton);
final int[] ballArray = {
R.drawable.ball1,
R.drawable.ball2,
R.drawable.ball3,
R.drawable.ball4,
R.drawable.ball5
};
//next button
nextbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
nextQuestion();
}
});
//previous button
prevbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
prevQuestion();
}
});
}
private void nextQuestion(){
mBallDisplay.setImageResource(ballArray[4]);
}
private void prevQuestion(){
}
}
The reason you can't access ballArray from within nextQuestion() is because it's declared in a separate method. If you want it accessible from within nextQuestion(), you would need to make it visible at that level:
ImageView mBallDisplay;
final int[] ballArray = {
R.drawable.ball1,
R.drawable.ball2,
R.drawable.ball3,
R.drawable.ball4,
R.drawable.ball5
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int quote;
mBallDisplay = (ImageView) findViewById(R.id.image_eightBall);
Button nextbutton = (Button) findViewById(R.id.nextbutton);
Button prevbutton = (Button) findViewById(R.id.prevbutton);
//next button
nextbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
nextQuestion();
}
});
//previous button
prevbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
prevQuestion();
}
});
}
private void nextQuestion(){
mBallDisplay.setImageResource(ballArray[4]);
}
private void prevQuestion(){
}
}
Do like this:-
public class MainActivity extends AppCompatActivity {
ImageView mBallDisplay;
int[] ballArray = {
R.drawable.ball1,
R.drawable.ball2,
R.drawable.ball3,
R.drawable.ball4,
R.drawable.ball5
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int quote;
mBallDisplay = (ImageView) findViewById(R.id.image_eightBall);
Button nextbutton = (Button) findViewById(R.id.nextbutton);
Button prevbutton = (Button) findViewById(R.id.prevbutton);
//next button
nextbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
nextQuestion();
}
});
//previous button
prevbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
prevQuestion();
}
});
}
private void nextQuestion(){
mBallDisplay.setImageResource(ballArray[4]);
}
private void prevQuestion(){
}
}

2nd layout Button is not working

This is my First Question & I'm a new android learner,
Suddenly in my ellipse 2nd layout button is not working;
after pressing button of my first layout it working & going to second layout.
But in 2nd layout my Button is not working, I tested it very simple code. Please check
public class MainActivity extends Activity {
Button b1,b2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button) findViewById(R.id.button1);
b2 = (Button) findViewById(R.id.button2);
b1.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
//setContentView(R.layout.activity_main_activity2); Need to remove
startActivity(new Intent(MainActivity.this,MainActivity2.class));
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
This is my 2nd activity code
public class MainActivity2 extends Activity {
EditText ed;
Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activity2);
ed = (EditText) findViewById(R.id.editText1);
button = (Button) findViewById(R.id.button21);
button.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
Toast.makeText(getBaseContext(), "Working", Toast.LENGTH_SHORT).show();
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_activity2, menu);
return true;
}
}
*You are simply changing the layout on first activity using setContentView(). You are not navigating from one activity to another.
Either you can register the button of layout 2 by onClicklistener after setting it on activity.
b1.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
setContentView(R.layout.activity_main_activity2);
button = (Button) findViewById(R.id.button21);
button.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
Toast.makeText(getBaseContext(),"Working",Toast.LENGTH_SHORT).show();
}
});
}
});
or you can goto your other activity
b1.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
// setContentView(R.layout.activity_main_activity2); remove
startActivity(new Intent(MainActivity.this,MainActivity2.class));
}
});

multi tasking in android

i get the Choreographer error The application may be doing too much work on its main thread.
In my main activity each time i launch the app or get back to the main activity.
From what i understand there's to many work to be done on one core (because i'm not using threads), so i have to find a solution which probably evolves threads and AsyncTask.
I was trying to figure out what exactly cause the cpu put his effort but i couldn't figure it out by myself.
Here's the code of the main activity which includes a navigation drawer:
public class MainActivity extends ActionBarActivity
implements View.OnClickListener {
private Animation animAlpha;
private Animation animRotate;
private MediaPlayer background_music;
static int is_login = 0;
private boolean isOpen = false;
private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mDrawerToggle;
private CharSequence mDrawerTitle;
private CharSequence mTitle;
private ViewFlipper flipper;
ImageButton messages,weekly_day_times,shabat_times,events;
private ViewGroup mContainerView1,mContainerView2,mContainerView3,mContainerView4;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
animAlpha = AnimationUtils.loadAnimation(this, R.anim.anim_alpha);
animRotate = AnimationUtils.loadAnimation(this, R.anim.anim_rotate);
background_music = MediaPlayer.create(this, R.raw.yedid_nefesh);
flipper = (ViewFlipper) findViewById(R.id.viewFlipper);
startFlipper();
background_music.start();
messages = (ImageButton) findViewById(R.id.messages_button);
weekly_day_times = (ImageButton) findViewById(R.id.weekly_times_button);
shabat_times = (ImageButton) findViewById(R.id.sat_times_button);
events = (ImageButton) findViewById(R.id.events_button);
messages.setOnClickListener(this);
weekly_day_times.setOnClickListener(this);
shabat_times.setOnClickListener(this);
events.setOnClickListener(this);
mContainerView1 = (ViewGroup) findViewById(R.id.add_shabat_container);
mContainerView2 = (ViewGroup) findViewById(R.id.add_weekly_container);
mContainerView3 = (ViewGroup) findViewById(R.id.add_messages_container);
mContainerView4 = (ViewGroup) findViewById(R.id.add_events_container);
findViewById(R.id.b_shabat_add).setOnClickListener(this);
findViewById(R.id.b_weekly_add).setOnClickListener(this);
findViewById(R.id.b_messages_add).setOnClickListener(this);
findViewById(R.id.b_events_add).setOnClickListener(this);
IntializeNavDrawer();
}
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
setButtonsAnimation(messages);
setButtonsAnimation(weekly_day_times);
setButtonsAnimation(shabat_times);
setButtonsAnimation(events);
}
private void setButtonsAnimation(ImageButton button) {
int rand = (int)(Math.random()*700);
Animation hyperspaceJump = AnimationUtils.loadAnimation(this, R.anim.hyperspace_jump);
hyperspaceJump.setStartOffset(rand);
button.startAnimation(hyperspaceJump);
}
/*
Initialize all list views in navigation drawer.
Handles actions of open or close drawer.
*/
private void IntializeNavDrawer() {
mTitle = mDrawerTitle = getTitle();
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow,
GravityCompat.START);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
null, R.string.drawer_open,
R.string.drawer_close) {
public void onDrawerClosed(View view) {
getSupportActionBar().setTitle(mTitle);
invalidateOptionsMenu(); // creates call to
// onPrepareOptionsMenu()
}
public void onDrawerOpened(View drawerView) {
getSupportActionBar().setTitle(mDrawerTitle);
invalidateOptionsMenu(); // creates call to
// onPrepareOptionsMenu()
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
}
/*
Initialize properties and start the background flipper
*/
private void startFlipper() {
flipper.setFlipInterval(5000);
flipper.setInAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_in));
flipper.setOutAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_out));
flipper.startFlipping();
}
#Override
protected void onResume() {
super.onResume();
flipper.startFlipping();
background_music.start();
}
#Override
public void setTitle(CharSequence title) {
mTitle = title;
getSupportActionBar().setTitle(mTitle);
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
#Override
public void onClick(View v) {
Intent i;
switch(v.getId())
{
case R.id.messages_button: {
i = new Intent(com.example.neotavraham.MainActivity.this, Messages.class);
startActivity(i);
return;
}
case R.id.sat_times_button: {
i = new Intent(com.example.neotavraham.MainActivity.this, ShabatPrays.class);
startActivity(i);
return;
}
case R.id.weekly_times_button: {
i = new Intent(com.example.neotavraham.MainActivity.this, WeeklyPrays.class);
startActivity(i);
return;
}
case R.id.events_button: {
i = new Intent(com.example.neotavraham.MainActivity.this, Events.class);
startActivity(i);
return;
}
case R.id.b_shabat_add:
if(isOpen){
removeItem(mContainerView1);
isOpen = false;
}else {
addItem(mContainerView1,R.layout.nav_drawer_l_changes_item_1);
isOpen =true;
}
return;
case R.id.b_weekly_add:
if(isOpen){
removeItem(mContainerView2);
isOpen = false;
}else {
addItem(mContainerView2,R.layout.nav_drawer_l_changes_item_1);
isOpen =true;
}
return;
case R.id.b_messages_add:
if(isOpen){
removeItem(mContainerView3);
isOpen = false;
}else {
addItem(mContainerView3,R.layout.nav_drawer_l_changes_item_2);
isOpen =true;
}
return;
case R.id.b_events_add:
if(isOpen){
removeItem(mContainerView4);
isOpen = false;
}else {
addItem(mContainerView4,R.layout.nav_drawer_l_changes_item_2);
isOpen =true;
}
return;
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
return super.onCreateOptionsMenu(menu);
}
#SuppressLint("NewApi")
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// The action bar home/up action should open or close the drawer.
// ActionBarDrawerToggle will take care of this.
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
return false;
}
#Override
protected void onStop() {
super.onStop();
background_music.pause();
flipper.stopFlipping();
}
/**** Method for Setting the Height of the ListView dynamically.
**** Hack to fix the issue of not showing all the items of the ListView
**** when placed inside a ScrollView ****/
public static void setListViewHeightBasedOnChildren(ListView listView) {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null)
return;
int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.UNSPECIFIED);
int totalHeight = 0;
View view = null;
for (int i = 0; i < listAdapter.getCount(); i++) {
view = listAdapter.getView(i, view, listView);
if (i == 0) {
view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, AbsListView.LayoutParams.WRAP_CONTENT));
}
view.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
totalHeight += view.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
listView.setLayoutParams(params);
listView.requestLayout();
}
private void addItem(ViewGroup mContainerView,int layout) {
// Instantiate a new "row" view.
final ViewGroup newView = (ViewGroup) LayoutInflater.from(this).inflate(
layout, mContainerView, false);
// Because mContainerView has android:animateLayoutChanges set to true,
// adding this view is automatically animated.
mContainerView.addView(newView, 2);
}
public void removeItem(ViewGroup mContainerView){
mContainerView.removeViewAt(2);
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Pass any configuration change to the drawer toggles
mDrawerToggle.onConfigurationChanged(newConfig);
}
}
Also here are puctures with and withougt the navigation bar:
I was hoping you will show me what cuase to that error and an example on how should i get over it.
thank you
Here is some information from the Android documentation site about multi-threading.
https://developer.android.com/training/multiple-threads/index.html
http://developer.android.com/guide/components/processes-and-threads.html
http://developer.android.com/guide/faq/commontasks.html#threading
You can look around the web for more tutorials.

How to Use button with Page indicator activity in android

I use the one Fragment and use three images for page slider. When i use this code(Button visible on 3rd screen) then the indicator not shifted or run only images are sliced. So, how i use the button and indicator together.
public class MainActivity extends FragmentActivity {
TestFragmentAdapter mAdapter;
ViewPager mPager;
PageIndicator mIndicator;
Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAdapter = new TestFragmentAdapter(getSupportFragmentManager());
mPager = (ViewPager)findViewById(R.id.pager);
mPager.setAdapter(mAdapter);
Button button = (Button) findViewById(R.id.nextbutton1);
CirclePageIndicator indicator = (CirclePageIndicator)findViewById(R.id.indicator);
mIndicator = indicator;
indicator.setViewPager(mPager);
float density = getResources().getDisplayMetrics().density;
indicator.setBackgroundColor(0xFFFFFFFF);
indicator.setRadius(7 * density);
indicator.setPageColor(0xFFFFFFFF);
indicator.setFillColor(0xFFE63F36);
indicator.setStrokeColor(0xFF000000);
indicator.setStrokeWidth((float) (0.5* density));
mPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageSelected(int position) {
Button button = (Button) findViewById(R.id.nextbutton1);
if(position==2) {
button.setVisibility(View.VISIBLE);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Do something in response to button click
Intent i=new Intent(MainActivity.this,Login.class);
startActivity(i);
}
});
} else {
button.setVisibility(View.GONE);
}
/* FragmentChangeListener listener = (FragmentChangeListener) //cast fragment at this position to FragmentChangeListener
listener.onCentered();*/
}
#Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
#Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
});
}

Video from Youtube API does not play onClick

I'm not sure exactly why but for some reason my videos do not seem to play when clicked. Instead they queue in the player but do not play. Has anyone experienced this before or have any idea how the issue can be resolved?
Source:
public class Home extends YouTubeBaseActivity implements
YouTubePlayer.OnInitializedListener,
YouTubeThumbnailView.OnInitializedListener {
public static final String API_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
public static final String VIDEO_ID = "o7VVHhK9zf0";
public static final String VIDEO1_ID = "xVHHJqntuXI";
public static final String VIDEO2_ID = "YWteQj_q3Ro";
public static final String VIDEO3_ID = "83ZgtqTw-mI";
public static final String VIDEO4_ID = "n5wMza29JwI";
private YouTubePlayer youTubePlayer;
private YouTubePlayerView youTubePlayerView;
private YouTubeThumbnailView youTubeThumbnailView1;
private YouTubeThumbnailView youTubeThumbnailView2;
private YouTubeThumbnailView youTubeThumbnailView3;
private YouTubeThumbnailView youTubeThumbnailView4;
private String[] drawerListViewItems;
private DrawerLayout drawerLayout;
private DrawerLayout mDrawerLayout;
private ListView drawerListView;
private ListView mDrawerList;
private ActionBarDrawerToggle actionBarDrawerToggle;
private ActionBarDrawerToggle mDrawerToggle;
private YouTubeThumbnailLoader youTubeThumbnailLoader;
ScrollView mainScrollView;
Button fav_up_btn1;
Button fav_dwn_btn1;
ArrayAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
final ActionBar actionBar = getActionBar();
actionBar.setCustomView(R.layout.actionbar_custom_view_home);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
// get list items from strings.xml
drawerListViewItems = getResources().getStringArray(R.array.items);
// get ListView defined in activity_main.xml
drawerListView = (ListView) findViewById(R.id.left_drawer);
// Set the adapter for the list view
drawerListView.setAdapter(new ArrayAdapter<String>(this,
R.layout.drawer_listview_item, drawerListViewItems));
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
actionBarDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
drawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description */
R.string.drawer_close /* "close drawer" description */
);
drawerLayout.setDrawerListener(actionBarDrawerToggle);
getActionBar().setDisplayHomeAsUpEnabled(true);
drawerLayout.setDrawerShadow(R.drawable.drawer_shadow,
GravityCompat.START);
youTubePlayerView = (YouTubePlayerView) findViewById(R.id.youtubeplayerview);
youTubePlayerView.initialize(API_KEY, this);
mainScrollView = (ScrollView) findViewById(R.id.groupScrollView);
youTubeThumbnailView1 = (YouTubeThumbnailView) findViewById(R.id.youtubethumbnailview1);
youTubeThumbnailView1.initialize(API_KEY, this);
fav_up_btn1 = (Button) findViewById(R.id.fav_up_btn1);
fav_up_btn1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
boolean favIsUp = fav_up_btn1
.getBackground()
.getConstantState()
.equals(getResources().getDrawable(
R.drawable.fav_up_btn1).getConstantState());
// set the background
fav_up_btn1
.setBackgroundResource(favIsUp ? R.drawable.fav_dwn_btn1
: R.drawable.fav_up_btn1);
}
});
youTubeThumbnailView1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
if (youTubePlayer != null) {
youTubePlayer.cueVideo(VIDEO1_ID);
youTubePlayer.play();
mainScrollView.smoothScrollTo(0, 0);
}
}
});
youTubeThumbnailView2 = (YouTubeThumbnailView) findViewById(R.id.youtubethumbnailview2);
youTubeThumbnailView2.initialize(API_KEY, this);
youTubeThumbnailView2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg1) {
if (youTubePlayer != null) {
youTubePlayer.cueVideo(VIDEO2_ID);
youTubePlayer.play();
mainScrollView.smoothScrollTo(0, 0);
}
}
});
youTubeThumbnailView3 = (YouTubeThumbnailView) findViewById(R.id.youtubethumbnailview3);
youTubeThumbnailView3.initialize(API_KEY, this);
youTubeThumbnailView3.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg1) {
if (youTubePlayer != null) {
youTubePlayer.cueVideo(VIDEO3_ID);
youTubePlayer.play();
mainScrollView.smoothScrollTo(0, 0);
}
}
});
youTubeThumbnailView4 = (YouTubeThumbnailView) findViewById(R.id.youtubethumbnailview4);
youTubeThumbnailView4.initialize(API_KEY, this);
youTubeThumbnailView4.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg1) {
if (youTubePlayer != null) {
youTubePlayer.cueVideo(VIDEO4_ID);
youTubePlayer.play();
mainScrollView.smoothScrollTo(0, 0);
}
}
});
}
#Override
public void onInitializationFailure(Provider provider,
YouTubeInitializationResult result) {
}
#Override
public void onInitializationSuccess(Provider provider,
YouTubePlayer player, boolean wasRestored) {
youTubePlayer = player;
if (!wasRestored) {
player.cueVideo(VIDEO_ID);
}
}
#Override
public void onInitializationFailure(YouTubeThumbnailView thumbnailView,
YouTubeInitializationResult error) {
}
#Override
public void onInitializationSuccess(YouTubeThumbnailView thumbnailView,
YouTubeThumbnailLoader thumbnailLoader) {
youTubeThumbnailLoader = thumbnailLoader;
thumbnailLoader
.setOnThumbnailLoadedListener(new ThumbnailLoadedListener());
youTubeThumbnailLoader.setVideo(VIDEO_ID);
}
private final class ThumbnailLoadedListener implements
YouTubeThumbnailLoader.OnThumbnailLoadedListener {
#Override
public void onThumbnailError(YouTubeThumbnailView arg0, ErrorReason arg1) {
}
#Override
public void onThumbnailLoaded(YouTubeThumbnailView arg0, String arg1) {
}
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
actionBarDrawerToggle.onConfigurationChanged(newConfig);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// call ActionBarDrawerToggle.onOptionsItemSelected(), if it returns
// true
// then it has handled the app icon touch event
if (actionBarDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Replace
youTubePlayer.cueVideo(VIDEO1_ID);
youTubePlayer.play();
With
youTubePlayer.loadVideo(VIDEO1_ID);

Categories

Resources