答案 0 :(得分:35)
此命令查找标有public class MainActivity extends AppCompatActivity {
private ViewPagerAdapter pagerAdapter;
private ViewPager mViewPager;
private Toolbar toolbar;
private TabLayout tabLayout;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
pagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(pagerAdapter);
tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
mViewPager.setCurrentItem(tab.getPosition());//setting current selected item over viewpager
switch (tab.getPosition()) {
case 0:
Log.e("TAG", "TAB1");
break;
case 1:
Log.e("TAG", "TAB2");
break;
case 2:
Log.e("TAG", "TAB3");
break;
}
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public static class PlaceholderFragment extends Fragment {
private static final String ARG_SECTION_NUMBER = "section_number";
public PlaceholderFragment() {
}
public static PlaceholderFragment newInstance(int sectionNumber) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
/*
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
TextView textView = (TextView) rootView.findViewById(R.id.recyclerView);
textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
return rootView;
}
}
*/
}
}
this is the fragment
public class SongsTab extends Fragment {
RecyclerView recyclerView;
private ArrayList<songInfo> songs= new ArrayList<>();
songAdapter songAdapter;
MediaPlayer mediaPlayer;
SeekBar seekBar;
SeekBar seekBar2;
private int seekForwardTime = 5000;
private int seekBackwardTime = 5000;
Cursor cursor;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v= inflater.inflate(R.layout.songs, container, false);
recyclerView =(RecyclerView)v.findViewById(R.id.recyclerView);
seekBar =(SeekBar)v.findViewById(R.id.seekBar);
songAdapter = new songAdapter(songs, getContext());
recyclerView.setAdapter(songAdapter);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(),
linearLayoutManager.getOrientation());
recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.addItemDecoration(dividerItemDecoration);
mediaPlayer = new MediaPlayer();
songAdapter.setOnitemClickListener(new songAdapter.OnitemClickListener() {
@Override
public void onItemclick(final songAdapter.ViewHolder holder, View v, songInfo obj, int position) {
System.gc();
int songPath = cursor.getColumnIndex(MediaStore.Audio.Media.DATA);
cursor.moveToPosition(position);
final String filename = cursor.getString(songPath);
if (mediaPlayer.isPlaying()) {
// mediaPlayer.stop();
mediaPlayer.reset();
// mediaPlayer.release();
//mediaPlayer = null;
} else try {
/* Intent intent = new Intent( MainActivity.this, Main2Activity.class );
startActivity(intent);*/
try {
mediaPlayer.setDataSource(filename);
} catch (IOException e1) {
e1.printStackTrace();
}
mediaPlayer.prepareAsync();
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener()
{
@Override
public void onPrepared (MediaPlayer mp){
mp.start();
seekBar.setProgress(0);
seekBar.setMax(mediaPlayer.getDuration());
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
mediaPlayer.seekTo(i);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
// });
// mediaPlayer.prepareAsync();
}
}
);
}catch(Exception e){
}
} ;
});
checkUserPermission();
return v;
}
private void checkUserPermission(){
if(Build.VERSION.SDK_INT>=23){
if(ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED){
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},123);
return;
}
}
loadSongs();
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode){
case 123:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED){
loadSongs();
}else{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Toast.makeText(getContext(), "Permission Denied", Toast.LENGTH_SHORT).show();
}
checkUserPermission();
}
break;
default:
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
private void loadSongs(){
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String selection = MediaStore.Audio.Media.IS_MUSIC+"!=0";
cursor = getActivity().getContentResolver().query(uri,null,selection,null,null);
if(cursor != null){
if(cursor.moveToFirst()){
do{
String name = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE));
String artist = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST));
int songPath = cursor.getColumnIndex(MediaStore.Audio.Media.DATA);
songInfo s = new songInfo(name,artist,songPath);
songs.add(s);
}while (cursor.moveToNext());
}
// cursor.close();
songAdapter = new songAdapter(songs, getActivity());
}
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
cursor.close();
}
/*
public void nextSong() {
int currentPosition = mediaPlayer.getCurrentPosition();
// check if seekForward time is lesser than song duration
if(currentPosition + seekForwardTime <= mediaPlayer.getDuration()){
// forward song
mediaPlayer.seekTo(currentPosition + seekForwardTime);
}else{
// forward to end position
mediaPlayer.seekTo(mediaPlayer.getDuration());
}
}
*/
public void play(){
mediaPlayer.start();
}
}
this is xml mainactivity
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.murarilal.musicmania.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
recycler view.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/recyclerView">
</android.support.v7.widget.RecyclerView>
<SeekBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/seekBar"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="60dp"
android:layout_alignParentEnd="true" />
</RelativeLayout>
的所有服务
有两种方法可以解决这个问题。
第一个:任何实现
doctrine.fixture.orm
的类都会自动注册此标记。
ORMFixtureInterface
第二个:您需要在
<?php namespace AppBundle\DataFixtures\ORM; use Doctrine\Bundle\FixturesBundle\ORMFixtureInterface; use Doctrine\Common\Persistence\ObjectManager; class LoadFixtures implements ORMFixtureInterface { public function load(ObjectManager $manager) { #your code } }
配置中手动将doctrine.fixture.orm
标记为DataFixtures
。
sevice.yml
答案 1 :(得分:7)
我尝试了@ Alexander的解决方案,但这对我不起作用。
我通过将标记服务添加到services.yml
文件包上的类Symfony doc来解决了同样的问题:
BlogBundle/Resources/config/services.yml
Services:
...
# Fixtures services
BlogBundle\DataFixtures\ORM\PostFixture:
tags: [doctrine.fixture.orm]
...
我的BlogBundle/DataFixtures/ORM/PostFixture.php
课程:
...
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
...
class PostFixture implements FixtureInterface
{
public function load(ObjectManager $manager)
{
...
}
}
来源灵感:Synfony doc -> Service container -> The autoconfigure Option
希望它能成为替代解决方案
答案 2 :(得分:3)
可重复使用的包的示例。
的src / Acme公司/捆绑/ UserBundle / DataFixtures / ORM / DataFixtures.php
<?php
namespace Acme\Bundle\UserBundle\DataFixtures\ORM;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
class DataFixtures extends Fixture
{
/**
* Load data fixtures with the passed EntityManager
*
* @param ObjectManager $manager
*/
public function load(ObjectManager $manager)
{
#your code
}
}
Acme\Bundle\UserBundle\DataFixtures\:
resource: '../../src/Acme/Bundle/UserBundle/DataFixtures/'
附加你的灯具数据:
php bin/console doctrine:fixtures:load --append
答案 3 :(得分:2)
〜/ dev / domain.lan / src / ProductBundle / DataFixtures / ORM / ProductF ixture.php
from tkinter import *
import random
window = Tk()
window.title("Dice")
def rollDice():
diceOutput = str(random.randint(1,6))
return diceOutput
roll = Button(window, text="Roll", command=rollDice)
output = Label(window, textvariable=diceOutput)
window.mainloop()
问题解决了必须添加服务:(app / config / services.yml)
.test {
transition: all 1s ease;
overflow:hidden;
max-height: 0;
}
.test.withAnimation {
max-height: 300px;
}
.test.withAnimation:after {
overflow:inherit;
}
答案 4 :(得分:1)
使用Doctrine \ Bundle \ FixturesBundle \ Fixture
class ProductFixture扩展了Fixture实现的FixtureInterface
请参阅文档:http://symfony.com/doc/current/bundles/DoctrineFixturesBundle/index.html
答案 5 :(得分:1)
在4.0.1中,我必须实现服务配置以显示Symfony我的DataFixtures文件夹:
在config / services.yaml
中services:
...
App\DataFixtures\:
resource: '../src/DataFixtures'
tags: [doctrine.fixture.orm]
如果我的类IMPLEMENTS FixtureInterface并且没有此配置,如果它是EXTENDS Fixture
答案 6 :(得分:0)
- doctrine / doctrine-fixtures-bundle:^ 3.0,
- Symfony ^ 3.3
第一
- 定义您的灯具。
<?php
namespace Where\MyFixtureBundle\FileFolder\IsLocated;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Nao\UserBundle\Entity\User;
class LoadData implements FixtureInterface
{
/**
* Load data fixtures with the passed EntityManager
*
* @param ObjectManager $manager
*/
public function load(ObjectManager $manager){
$object = new Entity();
$object->setFoo(bar)
...
$manager->persist($object);
$manager->flush();
}
}
接下来,在 捆绑包的service.yml文件 中定义服务,或直接在 “app / config / service.yml”(不推荐)
# Fixtures service
your_service.name:
class: Full\Namespce\With\TheClassFixtureName
tags: [doctrine.fixture.orm] <-- important
不要忘记,只是为了确保以下
composer du -o or composer dump-autoload -o
立即尝试执行命令以加载数据夹具。
答案 7 :(得分:0)
我还必须更新app / AppKernel.php并添加以下捆绑包数组:
new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle()
答案 8 :(得分:0)
在阅读了以上评论之后,我在@GuRu答案中找到了解决方法:
“ 第二个:您需要在sevice.yml配置中手动将doctrine.fixture.orm标记为DataFixtures ”。
然后在您的装置类中实现ORMFixtureInterface。
。实际上,我们必须在services.yml中添加其他配置来解决它。 重要的是要知道,我在symfony的〜3.4版本中注意到了这个问题。
最诚挚的问候