How to develop a Video Collage application in android? - Java for Android App Development

I am Developing an app related to "Video Collage", In this user can play multiple videos at a time in single layout file. For this i am using Video Views to play videos. but problem is user clicks save button the layout file was converted and saved as a video file into sdcard. If the user open saved file it plays multiple videos.
can any one give me an idea how can i do that?
I am using Following Code to play multiple videos at time.I am not sure I was in right direction.
Code:
public class MainActivity extends Activity {
String SrcPath = "sdcard/dhoo3.mp4";
String SrcPath2 = "sdcard/DCIM/Camera/20140206_124925.mp4";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview);
//myVideoView.setVideoURI(Uri.parse(SrcPath));
myVideoView.setVideoPath(SrcPath);
// MediaController mc=new MediaController(getApplicationContext());
// myVideoView.setMediaController(new MediaController(this));
// mc.setAnchorView(myVideoView);
//mc.setMediaPlayer(myVideoView);
//myVideoView.setMediaController(mc);
myVideoView.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
// TODO Auto-generated method stub
myVideoView.start();
myVideoView.requestFocus();
mp.start();
}
});
// myVideoView.start();
final VideoView myVideoView2 = (VideoView)findViewById(R.id.myvideoview2);
//myVideoView2.setVideoURI(Uri.parse(SrcPath2));
myVideoView2.setVideoPath(SrcPath2);
// myVideoView2.setMediaController(new MediaController(this));
myVideoView2.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
// TODO Auto-generated method stub
myVideoView2.start();
myVideoView2.requestFocus();
mp.start();
mp.setVolume(0f, 0f);
}
});
// myVideoView2.start();
}
}

Related

My Soundboard force closes every now and again

I have a problem: Everytime I click a button on my soundboard it has a 50/50 chance of force closing. the only thing I can think of is something in this line of code maybe:
Code:
public class MyMain extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//set up the button sounds
final MediaPlayer mpButtonClick = MediaPlayer.create(this, R.raw.money);
Button bmoney = (Button) findViewById(R.id.money);
bmoney.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mpButtonClick.start();
}
});
final MediaPlayer pButtonClick = MediaPlayer.create(this, R.raw.pants);
Button bpants = (Button) findViewById(R.id.pants);
bpants.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
pButtonClick.start();
}
});
...If you wish to later replay the media, then you must reset() and prepare() the MediaPlayer object before calling start() again. (create() calls prepare() the first time.)....
Click to expand...
Click to collapse
Thats probably the problem.
http://developer.android.com/guide/topics/media/index.html

Help JazzyViewPager and FragmentStatePagerAdapter

The problem is that the transitions wont work but all over the app is working fine. It's just the transition effects that aren't working. I've already tried all of them but no luck, the slides have their default transition. There are no errors in the codes too so I don't know what I've done wrong so please help. This is also my first app so please be kind. I didn't include the instantiateitem on pageradapter because if I do there will be a nullpointerexception. :/ I'm using JazzyViewPager for the transitions and Fragment State Pager Adapter. I've also searched for possible topics that might help me but none of them worked.
Main Activity:
Code:
public class MainActivity extends FragmentActivity {
private JazzyViewPager mJazzy;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupJazziness(TransitionEffect.CubeIn);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add("Toggle Fade");
String[] effects = this.getResources().getStringArray(R.array.jazzy_effects);
for (String effect : effects)
menu.add(effect);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getTitle().toString().equals("Toggle Fade")) {
mJazzy.setFadeEnabled(!mJazzy.getFadeEnabled());
} else {
TransitionEffect effect = TransitionEffect.valueOf(item.getTitle().toString());
setupJazziness(effect);
}
return true;
}
private void setupJazziness(TransitionEffect effect) {
mJazzy = (JazzyViewPager) findViewById(R.id.jazzy_pager);
mJazzy.setTransitionEffect(effect);
mJazzy.setAdapter(new FragmentAdapter(getSupportFragmentManager()));
mJazzy.setPageMargin(30);
}
FragmentStatePagerAdapter:
Code:
public class FragmentAdapter extends FragmentStatePagerAdapter{
public FragmentAdapter(FragmentManager fm) {
super(fm);
// TODO Auto-generated constructor stub
}
@Override
public Fragment getItem(int position)
{
// TODO Auto-generated method stub
Fragment fragment = new Fragment1();
switch(position){
case 0:
fragment = new Fragment1();
break;
case 1:
fragment = new Fragment2();
break;
case 2:
fragment = new Fragment3();
break;
}
return fragment;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 3;
}
@Override
public boolean isViewFromObject(View view, Object object) {
if(object != null){
return ((Fragment)object).getView() == view;
}else{
return false;
}
}
}
Fragment1:
Code:
public class Fragment1 extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View v = inflater.inflate(R.layout.fragment1_layout, null);
return v;
}
activity_main xml:
Code:
<com.jfeinstein.jazzyviewpager.JazzyViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:app1="http://schemas.android.com/apk/res/com.eight.yamjay"
android:id="@+id/jazzy_pager"
app1:style="cubeout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
This is the guide that I've been following.

Passing data between two fragments

Hello guys,
I have a list of fragments created and I want to delete these fragment by long pressing on them. However, before doing so I want dialog fragment to pop up and offer the user the choice to delete or not. I have created the two fragments but I can't get the data across each other. I can't give functionality to the 'OK' button. Here is my code:
Code:
public class CourseListFragment extends Fragment implements
OnItemClickListener, OnItemLongClickListener {
public static final String ARG_ITEM_ID = "course_list";
public static final String YES_NO = "modify";
Activity activity;
ListView courseListView;
ArrayList<Course> courses;
CourseListAdapter courseListAdapter;
CourseDAO courseDAO;
private GetEmpTask task;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
activity = getActivity();
courseDAO = new CourseDAO(activity);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.schedule_fragment_course_list,
container, false);
findViewsById(view);
task = new GetEmpTask(activity);
task.execute((Void) null);
courseListView.setOnItemClickListener(this);
courseListView.setOnItemLongClickListener(this);
return view;
}
private void findViewsById(View view) {
courseListView = (ListView) view.findViewById(R.id.list_course);
}
@Override
public void onItemClick(AdapterView<?> list, View view, int position,
long id) {
Course course = (Course) list.getItemAtPosition(position);
if (course != null) {
Bundle arguments = new Bundle();
arguments.putParcelable("selectedCourse", course);
CustomCourseDialogFragment customEmpDialogFragment = new CustomCourseDialogFragment();
customEmpDialogFragment.setArguments(arguments);
customEmpDialogFragment.show(getFragmentManager(),
CustomCourseDialogFragment.ARG_ITEM_ID);
}
}
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
// Show dialogFragment
FragmentManager fm = getActivity().getSupportFragmentManager();
CheckDialogFragment dialog = new CheckDialogFragment();
dialog.show(fm, YES_NO);
Course employee = (Course) parent.getItemAtPosition(position);
// Use AsyncTask to delete from database
courseDAO.deleteEmployee(employee);
courseListAdapter.remove(employee);
return true;
}
public class GetEmpTask extends AsyncTask<Void, Void, ArrayList<Course>> {
private final WeakReference<Activity> activityWeakRef;
public GetEmpTask(Activity context) {
this.activityWeakRef = new WeakReference<Activity>(context);
}
@Override
protected ArrayList<Course> doInBackground(Void... arg0) {
ArrayList<Course> courseList = courseDAO.getCourses();
return courseList;
}
@Override
protected void onPostExecute(ArrayList<Course> empList) {
if (activityWeakRef.get() != null
&& !activityWeakRef.get().isFinishing()) {
courses = empList;
if (empList != null) {
if (empList.size() != 0) {
courseListAdapter = new CourseListAdapter(activity,
empList);
courseListView.setAdapter(courseListAdapter);
} else {
Toast.makeText(activity, "No Course Records",
Toast.LENGTH_LONG).show();
}
}
}
}
}
/*
* This method is invoked from MainActivity onFinishDialog() method. It is
* called from CustomEmpDialogFragment when an employee record is updated.
* This is used for communicating between fragments.
*/
public void updateView() {
task = new GetEmpTask(activity);
task.execute((Void) null);
}
@Override
public void onResume() {
getActivity().setTitle("Course Schedule");
getActivity().getActionBar().setTitle("Course Schedule");
super.onResume();
}
}
//Dialog Fragment
Code:
public class CheckDialogFragment extends DialogFragment {
CourseListAdapter courseListAdapter;
CourseDAO courseDAO;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// TODO Auto-generated method stub
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
.setTitle("Do you want to delete?")
.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
// TODO Auto-generated method stub
}
})
.setNegativeButton(android.R.string.cancel,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
// TODO Auto-generated method stub
dialog.cancel();
}
});
return builder.create();
}
}
I have problems trying to get the data from onItemLongClick() of CourseListFragment to CourseListFragment. Any help would be greatly appreciated.

[Q] PreferenceFragment - problems in changing language preference

I have written the following code to allow user to display in chinese or english language. But when I select the language in the settings. There is no response and change in the App. I would like to ask if anyone could see the problems. Thank you for your help!
I have created the following folders
- values-en
- values-rTW
- values-rCN
Code:
public class AppPrefActivity extends Activity {
private SharedPreferences.OnSharedPreferenceChangeListener prefListener;
SharedPreferences pref;
public static final String PREF_LANGUAGE = "language_pref";
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
getFragmentManager().beginTransaction().replace(android.R.id.content, new PrefsFragement()).commit();
}
public static class PrefsFragement extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener{
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference);
}
@Override
public void onResume() {
super.onResume();
getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onPause() {
getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
super.onPause();
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if(key.equals(PREF_LANGUAGE))
{
Preference connectionPref = findPreference(key);
connectionPref.setSummary(sharedPreferences.getString(key, ""));
changeLanguagePref(sharedPreferences.getString(key, ""));
}
}
private void changeLanguagePref(String lang){
Locale locale = null;
if (lang.equals("Traditional Chinese")){
locale = new Locale("zh_rTW");
}else if (lang.equals("Simplified Chinese")){
locale = new Locale("zh_rCN");
}else{
locale = new Locale("en");
}
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
this.getResources().updateConfiguration(config, null);
}
}
}
This is part of the xml for language selection
Code:
<PreferenceCategory android:title="@string/pref_cat_app">
<ListPreference
android:title="@string/pref_def_lang"
android:entries="@array/app_language"
android:entryValues="@array/app_language"
android:defaultValue="English"
android:key="language_pref"/>
you need to recreate the activity after you reload all the resources.

Is there a reliable method to extract and display links from a Google search result page in an Android textView using web scraping in Java?

My need: I want to extract the links of websites that appear on Google search result page and display them in a textView. The Google search may vary according to the user's needs. The purpose of this (app) is to get the most related, nearest results for the user.
The mechanism is when the user inputs their search words and clicked on the button, the links that are extracted should appear on the textView.
Errors: I don't get an error in the code or any results on the textView.
My Question: Where have I gone wrong? How can I correct it? Is there any other way to do this?
TestHomeFragment.java
public class TestHomeFragment extends Fragment {
ImageButton b_search;
TextView search_webview;
String userLocation = "Sri Lanka";
TextView textView;
List<String> sriLankanUrls;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.test_home_fragment, container, false);
// --------------------------- Search Mechanism -----------------------------------------//
sriLankanUrls = new ArrayList<>();
b_search.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
String searchQuery="buy "+et_search.getText().toString()+ " in " + userLocation ;
new GoogleSearchScraperTask().execute();
}
}); return view;
}
private class GoogleSearchScraperTask extends AsyncTask<Void, Void, StringBuilder> {
@Override
protected StringBuilder doInBackground(Void... voids) {
StringBuilder resultBuilder = new StringBuilder();
try {
// Specify the Google search query
String searchQuery="buy "+et_search.getText().toString()+ " in " + userLocation ;
// Fetch the search results page
Document doc = Jsoup.connect("https://www.google.com/search?q=" + searchQuery).get();
// Extract sentences containing "https://"
Elements searchResults = doc.select("div.g");
for (Element result : searchResults) {
String snippet = result.select("span.st").text();
if (snippet.contains("http")) {
resultBuilder.append(snippet).append("\n");
}
}
} catch (IOException e) {
e.printStackTrace();
}return resultBuilder;
}
@Override
protected void onPostExecute(StringBuilder resultBuilder) {
super.onPostExecute(resultBuilder);
// Set the scraped sentences in the TextView
textView.setText(resultBuilder.toString());
}
}
}

Categories

Resources