文本字幕动态 [英] text for marquee dynamically

查看:185
本文介绍了文本字幕动态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能从列表视图的Java代码中添加文本在Android中,以选取框滚动。如果是的话可以请你让我知道如何?

如果需要,我将张贴使用code。
这是用于列表视图的XML如下:

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:方向=垂直>
     <的LinearLayout
        机器人:ID =@ + ID / linearLayout1
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:方向=横向>
    < / LinearLayout中>
    < ListView控件
        机器人:ID =@ + ID / audiolist_listView
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =0dp
        机器人:layout_gravity =底
        机器人:layout_weight =1
        机器人:背景=@绘制/ backgroundimg
        机器人:分=@绘制/梯度
        机器人:dividerHeight =1DP
        机器人:滚动条=垂直>
    < /&的ListView GT;< / LinearLayout中>

有关列表视图的Java类如下:

 公共类Audiovediolist扩展活动实现OnItemClickListener {
    私人的ListView audioList;
    私人意图frmHo​​me;
    私人的ArrayList<&HashMap的LT;字符串,字符串>> DataList控件;
    私人的HashMap<字符串,字符串>地图;
    私人的HashMap<字符串,字符串>数据;
    私人诠释Screen_Id;
    私人的AdView AdView的;
    字符串名称;
    字符串mSign [] = {白羊座Mesam,金牛座Vrushabham,双子Midhunam
            癌症-Karkatakam,狮子座-Simham,处女座 - 看呀,天秤座图拉
            天蝎-Vruchikam,人马 - Dhanussu,魔杰座-Makaram
            水瓶座Kumbham,双鱼座Meenam};
    整数mImages [] = {R.drawable.meshamu,R.drawable.vrushabhamu,
            R.drawable.medhunam,R.drawable.karkatakam,R.drawable.simham,
            R.drawable.kanya,R.drawable.tula,R.drawable.vruchikam,
            R.drawable.dhanussu,R.drawable.makaramu,R.drawable.kumbhamu,
            R.drawable.meenamu};    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_RIGHT_ICON);
        的setContentView(R.layout.list);
        frmHo​​me = getIntent();
        getIntentValues​​();
        initUI();
        setUI();
        uiListener();
    }    私人无效initUI(){
        audioList =(ListView控件)findViewById(R.id.audiolist_listView);
        DataList控件=新的ArrayList<&HashMap的LT;字符串,字符串>>();
        AD浏览=新的AdView(这一点,AdSize.SMART_BANNER,a150b89c23af3b2);
        的LinearLayout布局=(的LinearLayout)findViewById(R.id.linearLayout1);
        layout.setGravity(Gravity.TOP);
        layout.addView(AD浏览);
        adView.loadAd(新AdRequest中());
    }    私人无效uiListener(){
        audioList.setOnItemClickListener(本);
    }    私人无效getIntentValues​​(){
        字符串ID = frmHo​​me.getStringExtra(ACTIVITY_ID);
        Screen_Id =的Integer.parseInt(ID);
        如果(Screen_Id == 1){
            getWindow()。setFeatureDrawableResource(Window.FEATURE_RIGHT_ICON,
                    R.drawable.audioo);
            this.setTitle(getResources()的getString(R.string.audio));
            this.setTitleColor(getResources()的getColor(R.color.Beige));
        }其他{
            this.setTitle(getResources()的getString(R.string.video));
            this.setTitleColor(getResources()的getColor(R.color.Beige));
            getWindow()。setFeatureDrawableResource(Window.FEATURE_RIGHT_ICON,
                    R.drawable.videoo);
        }
    }    私人无效setAdapter(){
        SimpleAdapter适配器=新SimpleAdapter(这一点,Da​​taList控件,
                R.layout.list_row,新的String [] {图像,文本},新的INT [] {
                        R.id.audiolist_row_img,R.id.audiolist_row_tv});
        audioList.setAdapter(适配器);
    }    私人无效setUI(){
        为(int类型的= 0;一个与所述; = 11;一个++){
            地图=新的HashMap<字符串,字符串>();
            map.put(图像,+ mImages [A]);
            map.put(文本,mSign [一个]);
            dataList.add(地图);
            地图= NULL;
        }
    }    @覆盖
    保护无效调用onStart(){
        super.onStart();
        setAdapter();
    }    @覆盖
    公共无效onBack pressed(){
        super.onBack pressed();
        System.gc()的;
    }    @覆盖
    保护无效的onDestroy(){
        super.onDestroy();
        adView.destroy();
    }    / *
     *私有类NextTask扩展的AsyncTask<太虚,太虚,太虚> {ProgressDialog
     * progressDailog =新ProgressDialog(Audiovediolist.this);
     *
     *在preExecute @覆盖保护无效(){super.on preExecute();
     * progressDailog.setTitle(请等待);
     * progressDailog.setMessage(URL数据加载...);
     * progressDailog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
     * progressDailog.setCancelable(真); progressDailog.show(); }
     *
     * @燮pressWarnings(静态访问)
     *
     * @覆盖保护无效doInBackground(虚空...... PARAMS){返回NULL; }
     *
     * @覆盖保护无效onPostExecute(虚空结果){
     * progressDailog.dismiss(); }}
     * /
    @覆盖
    公共无效onItemClick(适配器视图<>母公司,观景,INT位置,
            长ID){
        数据= dataList.get(位置);
        //FinalConstants.AUDIO_VIDEO =清单;
        尝试{
            NetWorkCheck网络=新NetWorkCheck();
            如果(netWork.isNetWorkConnection(本)){
                如果(Screen_Id == 1){
                    //新NextTask()执行();
                    意图audioInt =新意图(getApplicationContext(),AudioView.class);
                     audioInt.setType(data.get(文本));                     startActivity(audioInt);
                }否则如果(Screen_Id == 2){
                    意图vedioInt =新意图(这一点,VideoPlayActivity.class);
                    vedioInt.setType(data.get(文本));
                    startActivity(vedioInt);
                }
            }其他{
                netWork.alert();
            }
        }赶上(例外五){
            e.printStackTrace();
            Toast.makeText(这一点,问题而ListItemClick
                    Toast.LENGTH_SHORT).show();
        }
    }
}

在code的音频播放器,我需要选择滚动如下文字

 公共类AudioView扩展活动实现OnClickListener {
    私人MediaPlayer的mMediaPlayer;
    私人ImageView的mPlay;
    私人ImageView的mPause;
    私人ImageView的mBack;
    私人ImageView的mFar;
    私人进度myProgressBar;
    私人布尔boolFlag = FALSE;
    私人布尔isPausedInCall = FALSE;
    私人字符串URL;
    私人TelephonyManager mTelephoneMgr;
    私人NotificationManager mNotificationManager;
    私人诠释SIMPLE_NOTFICATION_ID;
    私人TextView的电视;
    //私人布尔serviceRunning;
    通知notifyDetails;
    私人的AdView AdView的;
    @燮pressWarnings(德precation)
    @覆盖
    公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        。getWindow()requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        的setContentView(R.layout.marquee);
        Toast.makeText(这一点,请稍等.........,Toast.LENGTH_LONG).show();
        URL = getIntent()的getType()。
        initUI();
        uiListener();        mNotificationManager =(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        notifyDetails =新的通知(R.drawable.mulug_icon,网址,
                System.currentTimeMillis的());
        mTelephoneMgr =(TelephonyManager)getSystemService(TELEPHONY_SERVICE);
        如果(mTelephoneMgr!= NULL){
            mTelephoneMgr.listen(phoneStateListener,
                    PhoneStateListener.LISTEN_CALL_STATE);
        }
        /*if(FinalConstants.AUDIO_VIDEO ==列表项){
        LoginProgress任务=新LoginProgress();
        task.applicationContext = AudioView.this;
        task.execute();
    } * /
    }    私人无效initUI(){
        电视=(的TextView)findViewById(R.id.text);
        mBack =(ImageView的)findViewById(R.id.back);
        mPlay =(ImageView的)findViewById(R.id.play);
        mPause =(ImageView的)findViewById(R.id.pause);
        mFar =(ImageView的)findViewById(R.id.fwd);
        myProgressBar =(进度)findViewById(R.id.progressbar_Horizo​​ntal);
        myProgressBar.setProgressDrawable(getResources()。getDrawable(
                R.drawable.green_progress));
        myProgressBar.setProgress(0);
        AD浏览=新的AdView(这一点,AdSize.BANNER,a150b89c23af3b2);
        的LinearLayout布局=(的LinearLayout)findViewById(R.id.linearLayout1);
        layout.setGravity(Gravity.TOP);
        layout.addView(AD浏览);
        adView.loadAd(新AdRequest中());
        tv.setText(URL +更Deails点击www.mulugu.com);
        tv.setSelected(真);
    }
    私人无效uiListener(){
        mPlay.setOnClickListener(本);
        mPlay.setOnClickListener(本);
        mPause.setOnClickListener(本);
        mPause.setVisibility(android.view.View.INVISIBLE);
        mBack.setOnClickListener(本);
        mFar.setOnClickListener(本);
    }    私人线程MyThread的=新主题(){
        公共无效的run(){
            而(mMediaPlayer.getCurrentPosition()< mMediaPlayer
                    .getDuration()){
                尝试{
                    myProgressBar
                            .setProgress(mMediaPlayer.getCurrentPosition());
                }赶上(的Throwable t)的{
                }
            }
        }
    };    @覆盖
    保护无效调用onStart(){
        super.onStart();
        this.setProgressBarIndeterminateVisibility(真);
        尝试{
            如果(boolFlag == FALSE){
                的System.out.println(FinalConstants.URL +移动音频/+ URL +.MP3);
                mMediaPlayer = MediaPlayer.create(
                        这个,
                        Uri.parse(FinalConstants.URL +移动音频/+网址
                                +.MP3));
            }
            myProgressBar.setMax(mMediaPlayer.getDuration());
        }赶上(例外五){
            Toast.makeText(getApplicationContext(),数据不可用,
                    Toast.LENGTH_SHORT).show();
            Log.e(错误,数据不在该地址存在...);
            super.onBack pressed();
            e.printStackTrace();
        }
    }    @燮pressLint(NewApi)
    @覆盖
    公共无效onBack pressed(){
        super.onBack pressed();
        mMediaPlayer.stop();
        // myThread.stop();
        mNotificationManager.cancel(SIMPLE_NOTFICATION_ID);
        System.gc()的;
    }    @覆盖
    保护无效的onDestroy(){
        adView.destroy();
        super.onDestroy();
        System.gc()的;
    }    公共PhoneStateListener phoneStateListener =新PhoneStateListener(){
        @覆盖
        公共无效onCallStateChanged(INT状态,弦乐incomingNumber){
            如果(状态== TelephonyManager.CALL_STATE_RINGING){
                的System.out.println(振铃状态);
                如果(mMediaPlayer!= NULL){
                    pauseMedia();
                    isPausedInCall = TRUE;
                }
                notificationShow();
            }
            如果(状态== TelephonyManager.CALL_STATE_IDLE){
                的System.out.println(callState空闲);
                如果(mMediaPlayer!= NULL){
                    如果(isPausedInCall){
                        isPausedInCall = FALSE;
                        playMedia();
                    }
                }
            }
            如果(状态== TelephonyManager.CALL_STATE_OFFHOOK){
            }
            super.onCallStateChanged(州,incomingNumber);
        }
    };    私人无效pauseMedia(){
        mMediaPlayer.pause();
        changePlayerIcons(假);
    }    私人无效playMedia(){
        mMediaPlayer.start();
        changePlayerIcons(真);
    }
    公共无效的onClick(视图v){
        开关(v.getId()){
        案例R.id.play:
            如果(!boolFlag){
                尝试{
                    notificationShow();
                     mMediaPlayer.setLooping(假);
                     。mMediaPlayer prepareAsync();
                }赶上(例外五){
                    Toast.makeText(这一点,preparing,Toast.LENGTH_SHORT)
                            。显示();
                }
                boolFlag = TRUE;
                mMediaPlayer.start();
                myThread.start();
            }其他{
                notificationShow();
                mMediaPlayer.getCurrentPosition();
                mMediaPlayer.start();
            }
            changePlayerIcons(真);
            myProgressBar.setProgress(mMediaPlayer.getCurrentPosition());
            mMediaPlayer.setOnCompletionListener(新OnCompletionListener(){
                @覆盖
                公共无效onCompletion(MediaPlayer的为arg0){
                    changePlayerIcons(假);
                    myProgressBar.setProgress(0);
                    调用onStart();
                }
            });
            mMediaPlayer.setOn preparedListener(新在preparedListener(){
                @覆盖
                在prepared(MediaPlayer的MP)公共无效{
                }
            });
            打破;
        案例R.id.pause:
            mMediaPlayer.pause();
            mPlay.setVisibility(android.view.View.VISIBLE);
            mPause.setVisibility(android.view.View.INVISIBLE);
            打破;
        案例R.id.back:
            INT DUR = mMediaPlayer.getCurrentPosition();
            INT POS =(DUR&GT 10000杜尔 - 5000:0);
            mMediaPlayer.seekTo(POS)
            打破;
        案例R.id.fwd:
            INT CURPOS = mMediaPlayer.getCurrentPosition();
            INT dur2 = mMediaPlayer.getDuration();
            INT POS2 =(CURPOS + 5000> dur2 dur2:CURPOS + 5000);
            mMediaPlayer.seekTo(POS2);
            打破;
        }
    }    @燮pressWarnings(德precation)
    私人无效notificationShow(){
        上下文的背景下= getApplicationContext();
        CharSequence的contentTitle =Mulugu暗战;
        CharSequence的contentText = URL +每周predictions        意图notifyIntent =新意图(AudioView.this,AudioView.class);
        的PendingIntent意图= PendingIntent.getActivity(AudioView.this,0,
                notifyIntent,android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP);
        notifyDetails.setLatestEventInfo(背景下,contentTitle,contentText,
                意图);
        mNotificationManager.notify(SIMPLE_NOTFICATION_ID,notifyDetails);
    }    私人无效changePlayerIcons(布尔B){
        如果(B)的{
            mPlay.setVisibility(android.view.View.INVISIBLE);
            mPause.setVisibility(android.view.View.VISIBLE);
        }其他{
            mPlay.setVisibility(android.view.View.VISIBLE);
            mPause.setVisibility(android.view.View.INVISIBLE);
        }
    }    / *公共类LoginProgress扩展的AsyncTask<太虚,太虚,太虚> {        私人ProgressDialog对话框;
        保护上下文的applicationContext;        @覆盖
        保护无效onPostExecute(虚空结果){
            // TODO自动生成方法存根
            super.onPostExecute(结果);
            this.dialog.dismiss();
        }        @覆盖
        在preExecute保护无效(){
            this.dialog = ProgressDialog.show(ApplicationContext一数​​据加载,
                    加载.....,真正的);
        }        @覆盖
        保护无效doInBackground(虚空...... PARAMS){
            使用loadURL();
            返回null;
        }
        私人无效使用loadURL(){
            mMediaPlayer =新的MediaPlayer();
            mMediaPlayer.reset();
            尝试{
                mMediaPlayer.setDataSource(AudioView.this,Uri.parse(FinalConstants.URL +移动音频/+ getIntent()的getType()+.MP3)。);
                mMediaPlayer.setLooping(假); //设置循环
                mMediaPlayer prepare()。
                myProgressBar.setMax(mMediaPlayer.getDuration());
            }赶上(例外五){
                e.printStackTrace();
            }
        }
    } * /
}


解决方案

如果您需要移动的文字,也许这将有助于:

http://developer.android.com/guide/topics/resources/animation-resource.html#translate-element

如果您有这是太大的文字一个TextView,你想它走动,以便人们可以阅读整个事情,尝试的android:ellipsize =金字招牌在.xml文件,或在Java code:
textView.setEllipsize(TextUtils.TruncateAt.MARQUEE);

Is it possible to add text from java coding of a list view to marquee scroll in Android. If yes can you please let me know how?

If needed I shall post the code used. This was the XML for listview used is as follows

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
     <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
    </LinearLayout>
    <ListView
        android:id="@+id/audiolist_listView"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_gravity="bottom"
        android:layout_weight="1"
        android:background="@drawable/backgroundimg"
        android:divider="@drawable/gradient"
        android:dividerHeight="1dp"
        android:scrollbars="vertical" >
    </ListView>

</LinearLayout>

The java class for listview is as follows

public class Audiovediolist extends Activity implements OnItemClickListener {
    private ListView audioList;
    private Intent frmHome;
    private ArrayList<HashMap<String, String>> dataList;
    private HashMap<String, String> map;
    private HashMap<String, String> data;
    private int Screen_Id;
    private AdView adView;
    String name;
    String mSign[] = { "Aries-Mesam", "Taurus-Vrushabham", "Gemini-Midhunam",
            "Cancer-Karkatakam", "Leo-Simham", "Virgo-Kanya", "Libra-Tula",
            "Scorpio-Vruchikam", "Sagittarius-Dhanussu", "Capricorn-Makaram",
            "Aquarius-Kumbham", "Pisces-Meenam" };
    Integer mImages[] = { R.drawable.meshamu, R.drawable.vrushabhamu,
            R.drawable.medhunam, R.drawable.karkatakam, R.drawable.simham,
            R.drawable.kanya, R.drawable.tula, R.drawable.vruchikam,
            R.drawable.dhanussu, R.drawable.makaramu, R.drawable.kumbhamu,
            R.drawable.meenamu };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_RIGHT_ICON);
        setContentView(R.layout.list);
        frmHome = getIntent();
        getIntentValues();
        initUI();
        setUI();
        uiListener();
    }

    private void initUI() {
        audioList = (ListView) findViewById(R.id.audiolist_listView);
        dataList = new ArrayList<HashMap<String, String>>();
        adView = new AdView(this, AdSize.SMART_BANNER, "a150b89c23af3b2");
        LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout1);
        layout.setGravity(Gravity.TOP);
        layout.addView(adView);
        adView.loadAd(new AdRequest());
    }

    private void uiListener() {
        audioList.setOnItemClickListener(this);
    }

    private void getIntentValues() {
        String id = frmHome.getStringExtra("Activity_Id");
        Screen_Id = Integer.parseInt(id);
        if (Screen_Id == 1) {
            getWindow().setFeatureDrawableResource(Window.FEATURE_RIGHT_ICON,
                    R.drawable.audioo);
            this.setTitle(getResources().getString(R.string.audio));
            this.setTitleColor(getResources().getColor(R.color.Beige));
        } else {
            this.setTitle(getResources().getString(R.string.video));
            this.setTitleColor(getResources().getColor(R.color.Beige));
            getWindow().setFeatureDrawableResource(Window.FEATURE_RIGHT_ICON,
                    R.drawable.videoo);
        }
    }

    private void setAdapter() {
        SimpleAdapter adapter = new SimpleAdapter(this, dataList,
                R.layout.list_row, new String[] { "Image", "text" }, new int[] {
                        R.id.audiolist_row_img, R.id.audiolist_row_tv });
        audioList.setAdapter(adapter);
    }

    private void setUI() {
        for (int a = 0; a <= 11; a++) {
            map = new HashMap<String, String>();
            map.put("Image", "" + mImages[a]);
            map.put("text", mSign[a]);
            dataList.add(map);
            map = null;
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        setAdapter();
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        System.gc();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        adView.destroy();
    }

    /*
     * private class NextTask extends AsyncTask<Void,Void,Void> { ProgressDialog
     * progressDailog = new ProgressDialog(Audiovediolist.this);
     * 
     * @Override protected void onPreExecute() { super.onPreExecute();
     * progressDailog.setTitle("Please Wait");
     * progressDailog.setMessage("URL Data Loading ...");
     * progressDailog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
     * progressDailog.setCancelable(true); progressDailog.show(); }
     * 
     * @SuppressWarnings("static-access")
     * 
     * @Override protected Void doInBackground(Void... params) { return null; }
     * 
     * @Override protected void onPostExecute(Void result) {
     * progressDailog.dismiss(); } }
     */
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {
        data = dataList.get(position);
        //FinalConstants.AUDIO_VIDEO = "list";
        try {
            NetWorkCheck netWork = new NetWorkCheck();
            if (netWork.isNetWorkConnection(this)) {
                if (Screen_Id == 1) {
                    // new NextTask().execute();
                    Intent audioInt=new  Intent(getApplicationContext(),AudioView.class);
                     audioInt.setType(data.get("text"));

                     startActivity(audioInt);
                } else if (Screen_Id == 2) {
                    Intent vedioInt = new Intent(this, VideoPlayActivity.class);
                    vedioInt.setType(data.get("text"));
                    startActivity(vedioInt);
                }
            } else {
                netWork.alert();
            }
        } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(this, "Problem while ListItemClick",
                    Toast.LENGTH_SHORT).show();
        }
    }
}

The code for audio player where i need the text selected to scroll is as follows

public class AudioView extends Activity implements OnClickListener {
    private MediaPlayer mMediaPlayer;
    private ImageView mPlay;
    private ImageView mPause;
    private ImageView mBack;
    private ImageView mFar;
    private ProgressBar myProgressBar;
    private boolean boolFlag = false;
    private boolean isPausedInCall = false;
    private String url;
    private TelephonyManager mTelephoneMgr;
    private NotificationManager mNotificationManager;
    private int SIMPLE_NOTFICATION_ID;
    private TextView tv;
    // private boolean serviceRunning;
    Notification notifyDetails;
    private AdView adView;


    @SuppressWarnings("deprecation")
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        setContentView(R.layout.marquee);
        Toast.makeText(this,"please wait.........",Toast.LENGTH_LONG).show();
        url=getIntent().getType();
        initUI();
        uiListener();

        mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notifyDetails = new Notification(R.drawable.mulug_icon, url,
                System.currentTimeMillis());
        mTelephoneMgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
        if (mTelephoneMgr != null) {
            mTelephoneMgr.listen(phoneStateListener,
                    PhoneStateListener.LISTEN_CALL_STATE);
        }
        /*if(FinalConstants.AUDIO_VIDEO=="listitem"){
        LoginProgress task = new LoginProgress();
        task.applicationContext = AudioView.this;
        task.execute();
    }*/
    }

    private void initUI() {
        tv = (TextView) findViewById(R.id.text);
        mBack = (ImageView) findViewById(R.id.back);
        mPlay = (ImageView) findViewById(R.id.play);
        mPause = (ImageView) findViewById(R.id.pause);
        mFar = (ImageView) findViewById(R.id.fwd);
        myProgressBar = (ProgressBar) findViewById(R.id.progressbar_Horizontal);
        myProgressBar.setProgressDrawable(getResources().getDrawable(
                R.drawable.green_progress));
        myProgressBar.setProgress(0);
        adView = new AdView(this, AdSize.BANNER, "a150b89c23af3b2");
        LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout1);
        layout.setGravity(Gravity.TOP);
        layout.addView(adView);
        adView.loadAd(new AdRequest());
        tv.setText(url + "more Deails Click on www.mulugu.com");
        tv.setSelected(true);
    }
    private void uiListener() {
        mPlay.setOnClickListener(this);
        mPlay.setOnClickListener(this);
        mPause.setOnClickListener(this);
        mPause.setVisibility(android.view.View.INVISIBLE);
        mBack.setOnClickListener(this);
        mFar.setOnClickListener(this);
    }

    private Thread myThread = new Thread() {
        public void run() {
            while (mMediaPlayer.getCurrentPosition() < mMediaPlayer
                    .getDuration()) {
                try {
                    myProgressBar
                            .setProgress(mMediaPlayer.getCurrentPosition());
                } catch (Throwable t) {
                }
            }
        }
    };



    @Override
    protected void onStart() {
        super.onStart();
        this.setProgressBarIndeterminateVisibility(true);
        try {
            if (boolFlag == false) {
                System.out.println(FinalConstants.URL + "mobile-audio/" + url+ ".mp3");
                mMediaPlayer = MediaPlayer.create(
                        this,
                        Uri.parse(FinalConstants.URL + "mobile-audio/" + url
                                + ".mp3"));
            }
            myProgressBar.setMax(mMediaPlayer.getDuration());
        } catch (Exception e) {
            Toast.makeText(getApplicationContext(), "Data not available",
                    Toast.LENGTH_SHORT).show();
            Log.e("ERRORS", "Data Not Exist in that Url...");
            super.onBackPressed();
            e.printStackTrace();
        }
    }

    @SuppressLint("NewApi")
    @Override
    public void onBackPressed() {
        super.onBackPressed();
        mMediaPlayer.stop();
        // myThread.stop();
        mNotificationManager.cancel(SIMPLE_NOTFICATION_ID);
        System.gc();
    }

    @Override
    protected void onDestroy() {
        adView.destroy();
        super.onDestroy();
        System.gc();
    }



    public PhoneStateListener phoneStateListener = new PhoneStateListener() {
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            if (state == TelephonyManager.CALL_STATE_RINGING) {
                System.out.println("ringing state");
                if (mMediaPlayer != null) {
                    pauseMedia();
                    isPausedInCall = true;
                }
                notificationShow();
            }
            if (state == TelephonyManager.CALL_STATE_IDLE) {
                System.out.println("callState Idle");
                if (mMediaPlayer != null) {
                    if (isPausedInCall) {
                        isPausedInCall = false;
                        playMedia();
                    }
                }
            }
            if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
            }
            super.onCallStateChanged(state, incomingNumber);
        }
    };

    private void pauseMedia() {
        mMediaPlayer.pause();
        changePlayerIcons(false);
    }

    private void playMedia() {
        mMediaPlayer.start();
        changePlayerIcons(true);
    }
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.play:
            if (!boolFlag) {
                try {
                    notificationShow();
                     mMediaPlayer.setLooping(false);
                     mMediaPlayer.prepareAsync();
                } catch (Exception e) {
                    Toast.makeText(this, "preparing", Toast.LENGTH_SHORT)
                            .show();
                }
                boolFlag = true;
                mMediaPlayer.start();
                myThread.start();
            } else {
                notificationShow();
                mMediaPlayer.getCurrentPosition();
                mMediaPlayer.start();
            }
            changePlayerIcons(true);
            myProgressBar.setProgress(mMediaPlayer.getCurrentPosition());
            mMediaPlayer.setOnCompletionListener(new OnCompletionListener() {
                @Override
                public void onCompletion(MediaPlayer arg0) {
                    changePlayerIcons(false);
                    myProgressBar.setProgress(0);
                    onStart();
                }
            });
            mMediaPlayer.setOnPreparedListener(new OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mp) {
                }
            });
            break;
        case R.id.pause:
            mMediaPlayer.pause();
            mPlay.setVisibility(android.view.View.VISIBLE);
            mPause.setVisibility(android.view.View.INVISIBLE);
            break;
        case R.id.back:
            int dur = mMediaPlayer.getCurrentPosition();
            int pos = (dur > 10000 ? dur - 5000 : 0);
            mMediaPlayer.seekTo(pos);
            break;
        case R.id.fwd:
            int curpos = mMediaPlayer.getCurrentPosition();
            int dur2 = mMediaPlayer.getDuration();
            int pos2 = (curpos + 5000 > dur2 ? dur2 : curpos + 5000);
            mMediaPlayer.seekTo(pos2);
            break;
        }
    }

    @SuppressWarnings("deprecation")
    private void notificationShow() {
        Context context = getApplicationContext();
        CharSequence contentTitle = "Mulugu Running";
        CharSequence contentText = url + " Weekly Predictions";

        Intent notifyIntent = new Intent(AudioView.this, AudioView.class);
        PendingIntent intent = PendingIntent.getActivity(AudioView.this, 0,
                notifyIntent, android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP);
        notifyDetails.setLatestEventInfo(context, contentTitle, contentText,
                intent);
        mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);
    }

    private void changePlayerIcons(boolean b) {
        if (b) {
            mPlay.setVisibility(android.view.View.INVISIBLE);
            mPause.setVisibility(android.view.View.VISIBLE);
        } else {
            mPlay.setVisibility(android.view.View.VISIBLE);
            mPause.setVisibility(android.view.View.INVISIBLE);
        }
    }

    /*public class LoginProgress extends AsyncTask<Void, Void, Void> {

        private ProgressDialog dialog;
        protected Context applicationContext;

        @Override
        protected void onPostExecute(Void result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);
            this.dialog.dismiss();
        }

        @Override
        protected void onPreExecute() {
            this.dialog = ProgressDialog.show(applicationContext, "Data Loading",
                    "Loading .....", true);
        }

        @Override
        protected Void doInBackground(Void... params) {
            LoadUrl();
            return null;
        }
        private void LoadUrl() {
            mMediaPlayer = new MediaPlayer();
            mMediaPlayer.reset();
            try {
                mMediaPlayer.setDataSource(AudioView.this,Uri.parse(FinalConstants.URL + "mobile-audio/" + getIntent().getType()+ ".mp3"));
                mMediaPlayer.setLooping(false); // Set looping
                mMediaPlayer.prepare();
                myProgressBar.setMax(mMediaPlayer.getDuration());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }*/
}

解决方案

If you need to move text around, maybe this will help:

http://developer.android.com/guide/topics/resources/animation-resource.html#translate-element

If you have a TextView with a text that is too big and you want it to move around so people can read the whole thing, try android:ellipsize="marquee" in the .xml file, or in the Java code: textView.setEllipsize(TextUtils.TruncateAt.MARQUEE);

这篇关于文本字幕动态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆