Cwac Camera Video PreviewFragment - android

I am implementing Cwac-camera for video recording within my application. I am trying to figure out how can I setup my Video Preview Fragment which will playback the Video Recorded within the fragment with replay in infinite until the user has accepted or rejected the video preview.
This is my Activity where it calls for the video fragment.
#Override
public void onVideoRecorded(File video) {
videoPreviewFragment = VideoPreviewFragment.newInstance(video);
getSupportFragmentManager().beginTransaction().replace(R.id.sc_camera_container, picturePreviewFragment).commit();
}
And the VideoPreviewFragment I am using File to instead of URi
public class VideoPreviewFragment extends Fragment implements MediaPlayer.OnCompletionListener {
private static final String EXTRA_VIDEO_LOCATION = "extra_video_location";
public static VideoPreviewFragment newInstance(File video) {
VideoPreviewFragment fragment = new VideoPreviewFragment();
Bundle args = new Bundle(1);
args.putString(EXTRA_VIDEO_LOCATION, video.toString());
fragment.setArguments(args);
return fragment;
}
private VideoView videoView;
private File video;
private ImageButton btnAccept;
private ImageButton btnReject;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.sc_video_preview, container, false);
}
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
videoView = (VideoView) view.findViewById(R.id.sc_video);
btnAccept = (ImageButton) view.findViewById(R.id.sc_btn_accept);
btnAccept.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
getCameraActivity().onAccept(video);
}
});
btnReject = (ImageButton) view.findViewById(R.id.sc_btn_reject);
btnReject.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
getCameraActivity().onReject(video);
}
});
video = new File(getArguments().getString(EXTRA_VIDEO_LOCATION));
}
public SimpleCameraActivity getCameraActivity() {
return (SimpleCameraActivity) getActivity();
}
#Override
public void onSuccess() {
btnAccept.setEnabled(true);
btnReject.setEnabled(true);
}
#Override
public void onError() {
btnAccept.setEnabled(false);
btnReject.setEnabled(false);
}
#Override
public void onCompletion(MediaPlayer mp) {
Log.e("VIDEO PLAY", "END VIDEO PLAY");
}
}

Related

Call an dialog fragment method from Activity to Dialog Fragment

I am showing one dialog fragment (showing progress ) in my activity . Calling rest api methods are in my activity . Based on rest api results , I need to some progress in the dialog fragment . So I need to call a method of dialog fragment from activity . I tried with event bus , (Firing from Activity caught on Dialog Fragment ) - But events are not caught in dialog fragment . Is there any other solution ?
Fragment Code:
public class SyncProgressFragment extends BaseDialogFragment {
#BindView(R.id.layout_cancel)
LinearLayout layoutCancel;
#BindView(R.id.sync_with_master_breadcrumbs)
BreadcrumbsView syncWithMasterBreadCrumbs;
#BindView(R.id.master_breadcrumbs)
BreadcrumbsView masterBreadCrumbs;
#BindView(R.id.tvStep)
AppCompatTextView tvStep;
#BindView(R.id.tv_create_defect_title)
AppCompatTextView tvTitle;
private ThreadBus bus;
private FragmentManager manager;
private GoogleApiHelper googleApiHelper;
private Handler handler;
private Runnable runnable;
private boolean isOld;
private boolean isSync;
//private long requestId;
private BreadcrumbsView breadcrumbsView;
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
bus = AppController.getInstance().getBus();
bus.register(this);
googleApiHelper = AppController.getInstance().getGoogleApiHelper();
googleApiHelper.reconnect();
if (getArguments() != null) {
Bundle bundle = getArguments();
isOld = bundle.getBoolean(AppConstants.IS_OLD,false);
isSync = bundle.getBoolean(AppConstants.IS_OLD,false);
}
}
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
initUI();
}
private void initUI() {
if (isOld && isSync)
tvTitle.setText(getString(R.string.syncing_old_data_with_bo));
else if(!isOld && isSync)
tvTitle.setText(getString(R.string.syncing_data_with_bo));
else {
tvTitle.setText(getString(R.string.downloading_master_data));
}
if(isSync) {
breadcrumbsView = syncWithMasterBreadCrumbs;
syncWithMasterBreadCrumbs.setVisibility(View.VISIBLE);
masterBreadCrumbs.setVisibility(View.GONE);
tvStep.setText(getString(R.string.sending_data));
}
else{
breadcrumbsView = masterBreadCrumbs;
masterBreadCrumbs.setVisibility(View.VISIBLE);
syncWithMasterBreadCrumbs.setVisibility(View.GONE);
tvStep.setText(getString(R.string.getting_master_data));
}
}
private void initValues() {
handler = new Handler();
}
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
// request a window without the title
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(false);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
return dialog;
}
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_sync_progress, container, false);
ButterKnife.bind(this, view);
initValues();
return view;
}
#Override
public void onStart() {
super.onStart();
}
#Override
public void onResume() {
super.onResume();
}
#Override
public void onPause() {
super.onPause();
}
#Override
public void onStop() {
super.onStop();
}
#Override
public void onDestroy() {
super.onDestroy();
if (bus != null) {
bus.unregister(this);
}
try {
handler.removeCallbacks(runnable);
} catch (Exception e) {
}
}
#Override
public void onDestroyView() {
super.onDestroyView();
}
#Override
public void setCancelable(boolean cancelable) {
super.setCancelable(cancelable);
}
#Override
public void onCancel(DialogInterface dialog) {
super.onCancel(dialog);
}
#Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
try {
handler.removeCallbacks(runnable);
} catch (Exception e) {
}
}
#OnClick({R.id.img_close, R.id.layout_cancel})
public void onViewClicked(View view) {
switch (view.getId()) {
case R.id.layout_cancel:
case R.id.img_close:
dismissAllowingStateLoss();
break;
}
}
#Subscribe
public void onSyncGotResponse(SyncGotResponse syncGotResponse) {
Utilities.log(SyncProgressFragment.class,"onSyncGotResponse",""+syncGotResponse.isSuccess());
if(syncGotResponse.isSuccess()) {
breadcrumbsView.nextStep();
tvStep.setText(getString(R.string.synced_data_with_bo));
}
else
dismissAllowingStateLoss();
}
#Subscribe
public void onMasterGotResponse(MasterGotResponse masterGotResponse) {
Utilities.log(SyncProgressFragment.class,"onMasterGotResponse",""+masterGotResponse.isSuccess());
if(masterGotResponse.isSuccess()) {
tvStep.setText(getString(R.string.downloaded_data_from_bo));
breadcrumbsView.nextStep();
}
else
dismissAllowingStateLoss();
}
}
Activity Code:
#Override
public void dataSyncSuccess(DataSyncResponse dataSyncResponse) {
bus.post(new SyncGotResponse(true));
}
#Override
public void dataSyncFailure(String msg) {
UiUtils.showToast(getContext(), msg);
bus.post(new SyncGotResponse(false));
}
//Calling Rest Api method
if (CheckInternetConnection(getContext())) {
try {
presenter.data_sync();
Bundle bundle = new Bundle();
bundle.putBoolean(AppConstants.IS_OLD,false);
bundle.putBoolean(AppConstants.IS_SYNC,true);
syncProgressFragment.setArguments(bundle);
syncProgressFragment.setCancelable(false);
syncProgressFragment.show(getSupportFragmentManager(), syncProgressFragment.getTag());
} catch (JSONException e) {
e.printStackTrace();
}
} else {
ShowSanckBarShow();
}

android viewpager2 page buton controller

if the page is loaded, the button is active, if not, how can I do passive control?
What I want to do is, if the Viewpager Page is loaded, the button is active, if not, the Button is Passive. But I couldn't do any kind.
Is there anyone who can help?
If viewpager2 is installed Button enabled, if viewpager2 is not installed button false;
List<Movie> movieList = new ArrayList<>();
private ImageButton btn_down, btn_fav;
private Button btn_setter;
private DatabaseReference movies;
private IFirebaseLoadDone iFirebaseLoadDone;
public CartoonFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_cartoon, container, false);
movies = FirebaseDatabase.getInstance().getReference("Sports");
movies.keepSynced(true);
iFirebaseLoadDone = this;
loadMovie();
viewPager2 = view.findViewById(R.id.viewPager2_);
btn_down = view.findViewById(R.id.btn_down);
btn_setter = view.findViewById(R.id.btn_setter);
btn_fav = view.findViewById(R.id.btn_fav);
btn_down.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
SaveToGallery();
}
});
btn_setter.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
btn_fav.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
return view;
}
private void loadMovie() {
movies.addValueEventListener(this);
}
#Override
public void onFirebaseLoadSuccess(List<Movie> movieList) {
viewPagerAdapter = new ViewPagerAdapter(getContext(), movieList, viewPager2);
viewPager2.setAdapter(viewPagerAdapter);
}
#Override
public void onFirebasLoadFailed(String message) {
}
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot moviesSnapShot : dataSnapshot.getChildren())
movieList.add(moviesSnapShot.getValue(Movie.class));
Collections.reverse(movieList);
iFirebaseLoadDone.onFirebaseLoadSuccess(movieList);
viewPagerAdapter.notifyDataSetChanged();
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
iFirebaseLoadDone.onFirebasLoadFailed(databaseError.getMessage());
}
#Override
public void onDestroy() {
movies.removeEventListener(this);
super.onDestroy();
}
#Override
public void onResume() {
super.onResume();
}
#Override
public void onStop() {
movies.removeEventListener(this);
super.onStop();
}
}
Replace your methods with mine.
private void loadMovie() {
movies.addValueEventListener(this);
btn_down.setEnabled(false);
btn_fav.setEnabled(false);
btn_setter.setEnabled(false);
}
Firebase methods
#Override
public void onFirebaseLoadSuccess(List<Movie> movieList) {
viewPagerAdapter = new ViewPagerAdapter(getContext(), movieList, viewPager2);
viewPager2.setAdapter(viewPagerAdapter);
if(movieList!=null && !movieList.isEmpty()){
btn_down.setEnabled(true);
btn_fav.setEnabled(true);
btn_setter.setEnabled(true);
}
}
#Override
public void onFirebasLoadFailed(String message) {
btn_down.setEnabled(false);
btn_fav.setEnabled(false);
btn_setter.setEnabled(false);
}
There was an error loading
private void loadMovie() {
movies.addValueEventListener(this);
btn_down.setEnabled(false);
btn_fav.setEnabled(false);
btn_setter.setEnabled(false);
}
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageButton.setEnabled(boolean)' on a null object reference
at com.example.duvarlar.Fragment.CartoonFragment.loadMovie(CartoonFragment.java:386)
at com.example.duvarlar.Fragment.CartoonFragment.onCreateView(CartoonFragment.java:90)

Displaying and playing multiple video using youtube player API

I stumble upon issue playing more than 1 video using youtube API.
I found this article: Playing different youtube videos using Youtube Player API
Problem:
I cant find how it solved by keep more than 1 player on same page.
I'm trying to init 2 player with 2 different video code, but when i
tried to play 1 video, both run, then after 1 second, both stopped.
How can i fix it? Can anyone guide me?
Here's my code:
public class YoutubeTvFragment extends Fragment {
private static final String LOG = "Youtube TV";
private FragmentActivity myContext;
private YouTubePlayer YPlayer, YPlayer2;
private static final String YoutubeDeveloperKey = "";
private static final int RECOVERY_DIALOG_REQUEST = 1;
#Override
public void onAttach(Activity activity) {
if (activity instanceof FragmentActivity) {
myContext = (FragmentActivity) activity;
}
super.onAttach(activity);
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, Bundle savedInstanceState) {
// Defines the xml file for the fragment
View rootView = inflater.inflate(R.layout.fragment_tv_youtube, container, false);
YouTubePlayerSupportFragment youTubePlayerSupportFragment = YouTubePlayerSupportFragment.newInstance();
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
transaction.add(R.id.youtube_fragment, youTubePlayerSupportFragment).commit();
youTubePlayerSupportFragment.initialize(YoutubeDeveloperKey, new OnInitializedListener() {
#Override
public void onInitializationSuccess(YouTubePlayer.Provider arg0, YouTubePlayer youTubePlayer, boolean b) {
if (!b) {
YPlayer = youTubePlayer;
YPlayer.cueVideo("eCdXcZeKgxU");
//YPlayer.setShowFullscreenButton(false);
//YPlayer.pause();
//YPlayer.play();
}
}
#Override
public void onInitializationFailure(YouTubePlayer.Provider arg0, YouTubeInitializationResult arg1) {
// TODO Auto-generated method stub
}
});
YouTubePlayerSupportFragment youTubePlayerSupportFragment2 = YouTubePlayerSupportFragment.newInstance();
FragmentTransaction transaction2 = getChildFragmentManager().beginTransaction();
transaction2.add(R.id.youtube_fragment2, youTubePlayerSupportFragment2).commit();
youTubePlayerSupportFragment2.initialize(YoutubeDeveloperKey, new OnInitializedListener() {
#Override
public void onInitializationSuccess(YouTubePlayer.Provider arg0, YouTubePlayer youTubePlayer, boolean c) {
if (!c) {
YPlayer2 = youTubePlayer;
YPlayer2.cueVideo("jgnGD74BKoA");
//YPlayer2.setShowFullscreenButton(false);
//YPlayer2.pause();
//YPlayer2.play();
}
}
#Override
public void onInitializationFailure(YouTubePlayer.Provider arg0, YouTubeInitializationResult arg1) {
// TODO Auto-generated method stub
}
});
return rootView;
}
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
}

Android studio play an audio file without a button click

I recently paid someone to develop an experimental app for me. The app basically shows a picture with a couple of "buttons" in the corner that have other functions. Essentially, I also want an audio file to play automatically when the image is presented without having to click a button (this sort of function is already written into the script). I'm not a programmer (which is why I had to hire someone) but he couldn't figure out how to do this either. I just wondered whether anyone has any suggestions I can try?
Here is the code that controls the audio files:
public class ObjectFragment extends Fragment {
private int index;
private int trackID;
private int videoID;
private boolean visible;
private Integer[] imageIDs = {R.drawable.c1, R.drawable.c2, R.drawable.c3,
R.drawable.k1, R.drawable.k2, R.drawable.k3,
R.drawable.m1, R.drawable.m2, R.drawable.m3};
private Integer[] trackIDs = {R.raw.chatten, R.raw.chatten, R.raw.chatten,
R.raw.kobo, R.raw.kobo, R.raw.kobo,
R.raw.manu, R.raw.manu, R.raw.manu};
private Integer[] videos = {R.raw.chatten_vid2, R.raw.kobo_vid2, R.raw.manu_vid2};
static ObjectFragment newInstance(int i) {
ObjectFragment f = new ObjectFragment();
Bundle args = new Bundle();
args.putInt("index", i);
f.setArguments(args);
return f;
}
/**
* When creating, retrieve this instance's number from its arguments.
*/
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
index = getArguments() != null ? getArguments().getInt("index") : 0;
trackID = getArguments() != null ? getArguments().getInt("index") : 0;
}
#SuppressLint("SetTextI18n")
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
visible = true;
final View rootView = inflater.inflate(R.layout.fragment_collection_object, container, false);
final Button videoButton = (Button) rootView.findViewById(R.id.video);
videoButton.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if(MotionEventCompat.getActionMasked(motionEvent)==MotionEvent.ACTION_DOWN)
MainActivity.getPerson().formatString(System.nanoTime()-MainActivity.initTime, "button", motionEvent.getX(), motionEvent.getY(), "video");
return false;
}
});
final VideoView videoView = (VideoView) rootView.findViewById(R.id.videoView);
final TextView tv = (TextView) rootView.findViewById(R.id.word);
final int word;
((ImageView) rootView.findViewById(R.id.imageView)).setImageResource(imageIDs[index]);
//Change values here!!!
if(index<4) {
word=3;
tv.setText("Chatten");
videoButton.setBackgroundResource(R.drawable.snapchatten2);
videoID=0;
}
else if(index <8) {
word=7;
tv.setText("Kobo");
videoButton.setBackgroundResource(R.drawable.snapkobo2);
videoID=1;
}
else {
word=11;
tv.setText("Manu");
videoButton.setBackgroundResource(R.drawable.snapmanu2);
videoID=2;
}
rootView.findViewById(R.id.abc).setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
String text="";
if(word==3)
text = "Chatten";
else if(word==7)
text = "Kobo";
else if(word==11)
text="Manu";
if(MotionEventCompat.getActionMasked(motionEvent)==MotionEvent.ACTION_DOWN)
MainActivity.getPerson().formatString(System.nanoTime()-MainActivity.initTime, "button", motionEvent.getX(), motionEvent.getY(), "abc "+text);
return false;
}
});
rootView.findViewById(R.id.abc).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
tv.setVisibility(View.VISIBLE);
MainActivity.music.stop();
MainActivity.music.doInBackground(new Object[]{trackIDs[trackID]});
MainActivity.music.setLooping(false);
MainActivity.music.play();
while (!MainActivity.playBgMusic()) ;
}
});
rootView.findViewById(R.id.babylabs).setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (MotionEventCompat.getActionMasked(motionEvent) == MotionEvent.ACTION_DOWN)
MainActivity.getPerson().formatString(System.nanoTime() - MainActivity.initTime, "button", motionEvent.getX(), motionEvent.getY(), "babylabs");
return false;
}
});
rootView.findViewById(R.id.babylabs).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (tv.getVisibility() == View.VISIBLE) {
tv.setVisibility(View.GONE);
return;
}
visible = false;
MainActivity.back_counter = 1;
getActivity().onBackPressed();
}
});
videoButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
videoButton.setVisibility(View.INVISIBLE);
MainActivity.music.pause();
rootView.findViewById(R.id.imageView).setVisibility(View.INVISIBLE);
videoView.setVisibility(View.VISIBLE);
videoView.setVideoURI(Uri.parse("android.resource://" + getActivity().getPackageName() + "/" + videos[videoID]));
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mediaPlayer) {
videoView.start();
}
});
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mediaPlayer) {
videoView.setVisibility(View.GONE);
videoButton.setVisibility(View.VISIBLE);
rootView.findViewById(R.id.imageView).setVisibility(View.VISIBLE);
MainActivity.music.play();
}
});
}
});
return rootView;
}
}
Code snippet with ViewTreeObserver solution. It tells you when the image is drawn.
ViewTreeObserver vto = yourImage.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
#TargetApi(Build.VERSION_CODES.JELLY_BEAN)
#SuppressWarnings("deprecation")
#Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT < 16) {
yourImage.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
yourImage.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
// do additional stuff here
MainActivity.music.play();
}
});
You can add this code to your oncreate method. Don't forget to prepare your player before. Maybe you want to add a onloadcomplete listener.

Android fragments with Activitys that display OpenGL es 2.0

I have a dialog that I want to display, and I cannot. The activity that I'm calling it from has an opengl es SurfaceViewRenderer. Some code is below. The text 'here' shows, and some of the activity from the fragment is going on in the background (I see some of the println statements from there) but no fragment is visible. I do not see 'is visible' in the logs.
public void goToFrag() {
dDial = new MYDialogFragment();
Bundle args = new Bundle();
dDial.setArguments(args);
dDial.show(getFragmentManager(), "dDialog");
if (dDial.isVisible() ) System.out.println("is visible");
System.out.println("here");
}
so here's some more info. I tried to run the 'goToFrag()' method from the 'runOnUIThread()' method and the fragment appears, but only for a second. Then the PlayActivity (what I'm calling the activity that launches the Fragment and contains the GLSurfaceRenderer) disappears. After that I'm back at the activity that calls the PlayActivity. There's no error output that I can find.
//from OpenGL SurfaceViewRenderer...
public void goToFrag() {
mPlayActivity.runOnUiThread(new Runnable() {
#Override
public void run() {
mPlayActivity.goToFrag();
}
});
}
More code might help
public class APDuellingDialogFragment extends DialogFragment {
public boolean mDebugMessages = true;
public OnFragmentReturnListener mListener;
public View v;
public ListView mListView;
public RadioGroup radio_left_right;
public interface OnFragmentReturnListener {
public void onActivityResult(int requestCode, int resultCode, Intent data);
}
public APDuellingDialogFragment() {
mBT = new APDuellingBluetooth(this);
mList = new ArrayList<APDuellingBluetooth.MenuItem>();
mSocketsLaunched = false;
}
public static APDuellingDialogFragment newInstance() {
APDuellingDialogFragment dialog = new APDuellingDialogFragment();
//dialog.setStyle(DialogFragment.STYLE_NO_FRAME, R.style.AppTheme);
dialog.setShowsDialog(true);
dialog.setRetainInstance(true);
dialog.setCancelable(false);
return dialog;
}
#Override
public void onAttach(Activity activity) {
super.onAttach(activity);
if (mDebugMessages) System.out.println("on attach");
//...
// This makes sure that the container activity has implemented
// the callback interface. If not, it throws an exception
try {
mListener = (OnFragmentReturnListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnHeadlineSelectedListener");
}
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (mDebugMessages) System.out.println("on create");
}
#Override
public void onDismiss(DialogInterface dialog) {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
v = inflater.inflate(R.layout.fragment_ap_dueling, container, false);
if (mDebugMessages) System.out.println("on create view");
}
Button button_close = (Button)v.findViewById(R.id.duel_button_close);
button_close.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
dismiss();
}
});
Button button_rescan = (Button)v.findViewById(R.id.duel_button_rescan);
button_rescan.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if(mBT.isBluetoothSupported()) {
//...
}
}
});
radio_left_right = (RadioGroup) v.findViewById(R.id.duel_right_left_group);
radio_left_right.setOnCheckedChangeListener( new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
//...
}
});
Switch switch_audio = (Switch) v.findViewById(R.id.duel_switch_sound);
switch_audio.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
//...
}
});
mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
//...
return false;
}
});
return v;
}
public void restartGameFromFragment() {
if(mDebugMessages) System.out.println("restartgamefrom fragment");
Intent mIntent = prepareIntentForGame();
mListener.onActivityResult(AP.INTENT_ACTIVITY_DUEL_SETUP, Activity.RESULT_OK, mIntent);
dismiss();
}
public Intent prepareIntentForGame() {
Intent mIntent = new Intent();
//...
return mIntent;
}
#Override
public void onDestroy() {
super.onDestroy();
if (mDebugMessages) System.out.println("on destroy");
}
}
finally this:
public class MYActivityPlay extends Activity implements MYDuellingDialogFragment.OnFragmentReturnListener {
private MYGLSurfaceView myMYView;
public MYButtonManager mButtons;
public MYReadXML mXML;
public MYDuellingDialogFragment duelDialogFragment;
public RelativeLayout mTitleAndScoresView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mIntent = this.getIntent();
mMode = mIntent.getIntExtra(MY.INTENT_MODE_CONSTANT, MY.MODE_PLAY);
mIntentLevel = mIntent.getIntExtra(MY.INTENT_LEVEL_CONSTANT, 1);
mScore = mIntent.getLongExtra(MY.INTENT_SCORE_CONSTANT, 0);
mHealth = mIntent.getIntExtra(MY.INTENT_HEALTH_CONSTANT, MYDirector.FULL_HEALTH_CONST);
mPlayButtonPressedCount = mIntent.getIntExtra(MY.INTENT_PLAY_PRESSED_CONSTANT, 0);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
startSurfaceView();
if (mMode == MY.MODE_DUEL) goToFrag(); // <--here is problem!!
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//....
}
public void startSurfaceView() {
if (true ) {
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
Point size = new Point();
display.getSize(size);
mButtons = new MYButtonManager(this.getApplicationContext(), size.x ,size.y );
MYSound mSounds = new MYSound(this);
LayoutInflater mInflater = (LayoutInflater)getApplicationContext().getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
View mTitleAndScore = mInflater.inflate(R.layout.overlay_title_score, null);
myMYView = new MYGLSurfaceView(/*some stuff here*/);
RelativeLayout mRelative = new RelativeLayout(this);
mRelative.addView(myMYView);
mRelative.addView(mTitleAndScore);
mRelative.addView(mButtons);
setContentView(mRelative);
this.setupTitleAndScore();
}
}
}
this is the final piece.

Categories

Resources