Example usage for android.media MediaPlayer create

List of usage examples for android.media MediaPlayer create

Introduction

In this page you can find the example usage for android.media MediaPlayer create.

Prototype

public static MediaPlayer create(Context context, int resid) 

Source Link

Document

Convenience method to create a MediaPlayer for a given resource id.

Usage

From source file:mx.udlap.is522.tedroid.activity.ClassicGameActivity.java

/** Inicializa el media player que toca la msica */
private void setUpMediaPlayer() {
    if (isMusicEnabled()) {
        mediaPlayer = MediaPlayer.create(this, R.raw.the_distance);
        mediaPlayer.setLooping(true);//from  w w w.  j  ava  2s  . c o  m
        mediaPlayer.start();
    }
}

From source file:org.chromium.tools.audio_focus_grabber.AudioFocusGrabberListenerService.java

void playSound() {
    mMediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.ping);
    mMediaPlayer.setOnCompletionListener(mOnCompletionListener);
    mMediaPlayer.start();
}

From source file:com.marcopolci.paperwalletvalidator.MainActivity.java

@Override
protected void onStart() {
    super.onStart();
    try {/*from   w w w  . ja va2  s .  c  o m*/
        mPlayOk = MediaPlayer.create(this, R.raw.ok);
        mPlayErr = MediaPlayer.create(this, R.raw.error);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:me.willeponken.opendoor.AboutActivity.java

private void playEpicSaxGuy() {
    destroyMediaPlayer();
    mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.shortsaxguy);
    mediaPlayer.start();
}

From source file:com.poussiere_violette.poussieremagique.Destine_activity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //Forcer l'ecran  rester allum
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    setContentView(R.layout.activity_destine);

    j = getIntent();/*w w w  .  jav a 2s . c o  m*/
    destinNumber = j.getIntExtra("num", 1);
    destin = new Destin(destinNumber, getApplicationContext());

    conteneurDuDestin = findViewById(R.id.conteneur_du_destin);
    imagee = (ImageView) findViewById(R.id.fullscreen_content);
    tv = (TextView) findViewById(R.id.sous_titres);
    imagee.setImageResource(destin.getImage());
    sousTitreColor = destin.getSousTitresColor();
    tv.setTextColor(ContextCompat.getColor(getApplicationContext(), sousTitreColor));

    isThreadRunning = true;
    //On cree un handler qui va executer du code dans l'IU thread  chaque fois qu'il recevra un message, meme vide...
    handler = new Handler() {

        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            tv.setText(sousTitre);
            if (clickToLeave) {
                imagee.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent in = new Intent(Destine_activity.this, QueFaire.class);
                        in.putExtra("num", destinNumber);
                        startActivity(in);
                        overridePendingTransition(R.anim.blink_no_repeat, R.anim.inverse_blink_no_repeat);
                    }
                });
            }

        }

    };

    thread = new Thread(new Runnable() {
        @Override
        public void run() {
            isThreadRunning = true;

            if (destin.getMusic() != 0) {
                mPlayer = MediaPlayer.create(Destine_activity.this, destin.getMusic());
                mPlayer.start();
                mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                    @Override
                    public void onCompletion(MediaPlayer mediaPlayer) {
                        Intent in = new Intent(Destine_activity.this, QueFaire.class);
                        in.putExtra("num", destinNumber);
                        startActivity(in);
                        overridePendingTransition(R.anim.blink_no_repeat, R.anim.inverse_blink_no_repeat);
                    }
                });

            }

            int[] text = destin.getNouvelles();
            tabSize = destin.getTabSize();
            timeSoutitre = destin.getTimeSousTitre();
            while (isThreadRunning) {
                try {
                    thread.sleep(1000);
                } catch (InterruptedException ie) {
                }

                for (bc = 0; bc < tabSize; bc++) {
                    sousTitre = getResources().getString(text[bc]);

                    if (bc == (tabSize - 1))
                        clickToLeave = true;
                    handler.sendEmptyMessage(0);

                    try {
                        thread.sleep(timeSoutitre);
                    } catch (InterruptedException ie) {
                    }

                }

                isThreadRunning = false;

            }
        }
    });
    thread.start();

}

From source file:edu.ksu.cs.a4vm.bse.MorphologyCount.java

@Override
public void onResume() {
    super.onResume();
    test = "Resume called...";
    final MediaPlayer btnChangeSound = MediaPlayer.create(getApplicationContext(), R.raw.button_changed);
    final MediaPlayer limitRchdSound = MediaPlayer.create(getApplicationContext(), R.raw.limit_reached);
    initVals = (HashSet<String>) SharedPrefUtil.getValue(getApplicationContext(),
            Constant.PREFS_BULL_MORPHOLOGY_INFO, morphKey);
    /*morphologyLabels = (HashSet<String>) SharedPrefUtil.getValue(getApplicationContext(),
        Constant.PREFS_FILE_MORPH_INFO,Constant.KEY_MORPHOLOGY);*/
    morphologyLabels = (HashSet<String>) SharedPrefUtil.getValue(getApplicationContext(),
            Constant.PREFS_GRP_MORPH_CONFIG, grpKey);
    TableLayout table = new TableLayout(this);
    FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    table.setLayoutParams(lp);//w  w w .  ja  va 2 s.  co m
    table.setShrinkAllColumns(true);
    table.setStretchAllColumns(true);

    TableLayout.LayoutParams rowLp = new TableLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 0.5f);
    TableRow.LayoutParams cellLp = new TableRow.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1.0f);

    TableRow.LayoutParams cell1Lp = new TableRow.LayoutParams(60, 120, 1.0f);

    if (initVals != null) {
        for (String Val : initVals) {
            String[] values = Val.split("=");
            if (values != null && values.length == 2 && values[0].equalsIgnoreCase("Normal")) {
                NormalCount = Integer.valueOf(values[1].trim().substring(0, values[1].trim().indexOf("(")));
                NormalProp = Double.valueOf(values[1].trim().substring(values[1].trim().indexOf("(") + 1,
                        values[1].trim().indexOf("%")));
            } else if (morphologyLabels != null) {
                for (String label : morphologyLabels) {
                    String[] lbls = label.split("=");
                    if (lbls != null && lbls.length == 2 && lbls[1].equalsIgnoreCase(values[0])) {
                        if (lbls[0].equalsIgnoreCase("Morphology Field 2")) {
                            Lb2Count = Integer
                                    .valueOf(values[1].trim().substring(0, values[1].trim().indexOf("(")));
                            Lb2Prop = Double.valueOf(values[1].trim().substring(
                                    values[1].trim().indexOf("(") + 1, values[1].trim().indexOf("%")));
                        } else if (lbls[0].equalsIgnoreCase("Morphology Field 3")) {
                            Lb3Count = Integer
                                    .valueOf(values[1].trim().substring(0, values[1].trim().indexOf("(")));
                            Lb3Prop = Double.valueOf(values[1].trim().substring(
                                    values[1].trim().indexOf("(") + 1, values[1].trim().indexOf("%")));
                        } else if (lbls[0].equalsIgnoreCase("Morphology Field 4")) {
                            Lb4Count = Integer
                                    .valueOf(values[1].trim().substring(0, values[1].trim().indexOf("(")));
                            Lb4Prop = Double.valueOf(values[1].trim().substring(
                                    values[1].trim().indexOf("(") + 1, values[1].trim().indexOf("%")));
                        } else if (lbls[0].equalsIgnoreCase("Morphology Field 5")) {
                            Lb5Count = Integer
                                    .valueOf(values[1].trim().substring(0, values[1].trim().indexOf("(")));
                            Lb5Prop = Double.valueOf(values[1].trim().substring(
                                    values[1].trim().indexOf("(") + 1, values[1].trim().indexOf("%")));
                        } else if (lbls[0].equalsIgnoreCase("Morphology Field 6")) {
                            Lb6Count = Integer
                                    .valueOf(values[1].trim().substring(0, values[1].trim().indexOf("(")));
                            Lb6Prop = Double.valueOf(values[1].trim().substring(
                                    values[1].trim().indexOf("(") + 1, values[1].trim().indexOf("%")));
                        } else if (lbls[0].equalsIgnoreCase("Morphology Field 7")) {
                            Lb7Count = Integer
                                    .valueOf(values[1].trim().substring(0, values[1].trim().indexOf("(")));
                            Lb7Prop = Double.valueOf(values[1].trim().substring(
                                    values[1].trim().indexOf("(") + 1, values[1].trim().indexOf("%")));
                        } else if (lbls[0].equalsIgnoreCase("Morphology Field 8")) {
                            Lb8Count = Integer
                                    .valueOf(values[1].trim().substring(0, values[1].trim().indexOf("(")));
                            Lb8Prop = Double.valueOf(values[1].trim().substring(
                                    values[1].trim().indexOf("(") + 1, values[1].trim().indexOf("%")));
                        }
                    }
                }
            }
        }
    }

    Constant.sum = NormalCount + Lb2Count + Lb3Count + Lb4Count + Lb5Count + Lb6Count + Lb7Count + Lb8Count;

    row = new TableRow(this);
    btn1 = new Button(this);
    btn1.setId(R.id.button1);
    btn1.setText("Normal:" + NormalCount + "(" + String.format("%.2f", NormalProp) + "%)");
    btn1.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.button));
    btn1.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white));
    row.addView(btn1, cellLp);
    table.addView(row, rowLp);
    setContentView(table);
    if (morphologyLabels != null) {
        Iterator<String> it;

        TableRow row2 = new TableRow(this);
        TableRow row3 = new TableRow(this);
        TableRow row4 = new TableRow(this);
        TableRow row5 = new TableRow(this);

        it = morphologyLabels.iterator();
        while (it.hasNext()) {
            String label = it.next();
            String text[] = label.split("=");
            if (label.contains("Morphology Field 2")) {
                btn2 = new Button(this);
                btn2.setId(R.id.button2);
                if (text != null && text.length == 2) {
                    btn2.setText(text[1] + ":" + Lb2Count + "(" + String.format("%.2f", Lb2Prop) + "%)");
                }
                btn2.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.button2));
                btn2.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white));
                btn2.setHeight(300);
                row2.addView(btn2);
            } else if (label.contains("Morphology Field 4")) {
                btn4 = new Button(this);
                btn4.setId(R.id.button4);
                if (text != null && text.length == 2) {
                    btn4.setText(text[1] + ":" + Lb4Count + "(" + String.format("%.2f", Lb4Prop) + "%)");
                }
                btn4.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.button4));
                btn4.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white));
                btn4.setHeight(300);
                row3.addView(btn4);
            } else if (label.contains("Morphology Field 6")) {
                btn6 = new Button(this);
                btn6.setId(R.id.button6);
                if (text != null && text.length == 2) {
                    btn6.setText(text[1] + ":" + Lb6Count + "(" + String.format("%.2f", Lb6Prop) + "%)");
                }
                btn6.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.button6));
                btn6.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white));
                btn6.setHeight(300);
                row4.addView(btn6);
            } else if (label.contains("Morphology Field 8")) {
                btn8 = new Button(this);
                btn8.setId(R.id.button8);
                if (text != null && text.length == 2) {
                    btn8.setText(text[1] + ":" + Lb8Count + "(" + String.format("%.2f", Lb8Prop) + "%)");
                }
                btn8.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.button8));
                btn8.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white));
                //btn = new Button(this);
                btn8.setHeight(300);
                row5.addView(btn8);
                //row5.addView(btn);
            }
        }

        it = morphologyLabels.iterator();
        while (it.hasNext()) {
            String label = it.next();
            String text[] = label.split("=");
            if (label.contains("Limit")) {
                if (text != null && text.length == 2) {
                    limit = Integer.valueOf(text[1]);
                }
            } else if (label.contains("Morphology Field 3")) {
                btn3 = new Button(this);
                btn3.setId(R.id.button3);
                if (text != null && text.length == 2) {
                    btn3.setText(text[1] + ":" + Lb3Count + "(" + String.format("%.2f", Lb3Prop) + "%)");
                }
                btn3.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.button3));
                btn3.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white));
                btn3.setHeight(300);
                row2.addView(btn3);
            } else if (label.contains("Morphology Field 5")) {
                btn5 = new Button(this);
                btn5.setId(R.id.button5);
                if (text != null && text.length == 2) {
                    btn5.setText(text[1] + ":" + Lb5Count + "(" + String.format("%.2f", Lb5Prop) + "%)");
                }
                btn5.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.button5));
                btn5.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white));
                btn5.setHeight(300);
                row3.addView(btn5);
            } else if (label.contains("Morphology Field 7")) {
                btn7 = new Button(this);
                btn7.setId(R.id.button7);
                if (text != null && text.length == 2) {
                    btn7.setText(text[1] + ":" + Lb7Count + "(" + String.format("%.2f", Lb7Prop) + "%)");
                }
                btn7.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.button7));
                btn7.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white));
                btn7.setHeight(300);
                row4.addView(btn7);
            }

        }

        table.addView(row2, rowLp);
        table.addView(row3, rowLp);
        table.addView(row4, rowLp);
        table.addView(row5, rowLp);

    }

    row = new TableRow(this);

    btn = new Button(this);
    btn.setId(R.id.button);
    btn.setText("Edit Morphology Counts");
    btn.setGravity(Gravity.CENTER);
    row.addView(btn, cell1Lp);

    tv = new TextView(this);
    tv.setId(R.id.totals);
    tv.setText("Total Count:" + Constant.sum);
    tv.setGravity(Gravity.CENTER);
    row.addView(tv, cell1Lp);
    //table.addView(row, rowLp);
    //setContentView(table);

    //row = new TableRow(this);

    table.addView(row, rowLp);
    setContentView(table);

    //initializing morphology counts
    if (initVals == null) {
        morphologyCounts = new HashSet<String>();
        if (btn1 != null) {
            String initEntry = btn1.getText().toString().trim().replace(":", "=");
            morphologyCounts.add(initEntry);
        }
        if (btn2 != null) {
            String initEntry = btn2.getText().toString().trim().replace(":", "=");
            morphologyCounts.add(initEntry);
        }
        if (btn3 != null) {
            String initEntry = btn3.getText().toString().trim().replace(":", "=");
            morphologyCounts.add(initEntry);
        }
        if (btn4 != null) {
            String initEntry = btn4.getText().toString().trim().replace(":", "=");
            morphologyCounts.add(initEntry);
        }
        if (btn5 != null) {
            String initEntry = btn5.getText().toString().trim().replace(":", "=");
            morphologyCounts.add(initEntry);
        }
        if (btn6 != null) {
            String initEntry = btn6.getText().toString().trim().replace(":", "=");
            morphologyCounts.add(initEntry);
        }
        if (btn7 != null) {
            String initEntry = btn7.getText().toString().trim().replace(":", "=");
            morphologyCounts.add(initEntry);
        }
        if (btn8 != null) {
            String initEntry = btn8.getText().toString().trim().replace(":", "=");
            morphologyCounts.add(initEntry);
        }
    } else {
        morphologyCounts = new HashSet<String>();
        for (String initVal : initVals) {
            morphologyCounts.add(initVal);
        }
    }

    if (btn != null) {
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //SharedPrefUtil.saveGroup(getApplicationContext(),Constant.PREFS_BULL_MORPHOLOGY_INFO,morphKey,morphologyCounts);
                Intent gotoEditCount = new Intent(getApplicationContext(), EditMorphologyCounts.class);
                gotoEditCount.putExtra("morphKey", morphKey);
                startActivity(gotoEditCount);
            }
        });
    }
    if (btn1 != null) {
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //final MediaPlayer btnChangeSound = MediaPlayer.create(getApplicationContext(),R.raw.button_changed);
                if (currentButton == null)
                    currentButton = "btn1";
                else {
                    if (!"btn1".equalsIgnoreCase(currentButton)) {
                        //make sound
                        btnChangeSound.start();
                        currentButton = "btn1";
                    }
                }
                try {
                    String[] btnStrings = btn1.getText().toString().trim().split(":");
                    String btnLbl = btnStrings[0].trim();
                    String btnCount = btnStrings[1].trim().substring(0, btnStrings[1].trim().indexOf("("));
                    String btnprop = btnStrings[1].trim().substring(btnStrings[1].trim().indexOf("(") + 1,
                            btnStrings[1].trim().indexOf("%"));

                    NormalCount = Integer.valueOf(btnCount);
                    NormalProp = Double.valueOf(btnprop);
                    if (Constant.sum < limit) {
                        String oldTxt = btnLbl + "=" + NormalCount + "(" + String.format("%.2f", NormalProp)
                                + "%" + ")";
                        morphologyCounts.remove(oldTxt);
                        NormalCount = NormalCount + 1;
                        Constant.sum = Constant.sum + 1;
                        NormalProp = (NormalCount * 100.0) / Constant.sum;
                        String newTxt = btnLbl + ":" + NormalCount + "(" + String.format("%.2f", NormalProp)
                                + "%" + ")";
                        btn1.setText(newTxt);
                        newTxt = btnLbl + "=" + NormalCount + "(" + String.format("%.2f", NormalProp) + "%"
                                + ")";
                        morphologyCounts.add(newTxt);
                    } else if (Constant.sum == limit) {
                        limitRchdSound.start();
                        Constant.sum++;
                    }

                    if (Constant.sum < limit)
                        tv.setText("Total Count:" + Constant.sum);
                    else
                        tv.setText("Total Count:" + limit);
                } catch (Exception e) {
                    e.printStackTrace();
                    Toast.makeText(getApplicationContext(), "Error occured. Restart and try again",
                            Toast.LENGTH_SHORT).show();
                }

            }
        });
    }

    if (btn2 != null) {
        tv.setText("Total Count:" + Constant.sum);
        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //final MediaPlayer btnChangeSound = MediaPlayer.create(getApplicationContext(),R.raw.button_changed);
                if (currentButton == null)
                    currentButton = "btn2";
                else {
                    if (!"btn2".equalsIgnoreCase(currentButton)) {
                        //make sound
                        btnChangeSound.start();
                        currentButton = "btn2";
                    }
                }

                try {
                    String[] btnStrings = btn2.getText().toString().trim().split(":");
                    String btnLbl = btnStrings[0].trim();
                    String btnCount = btnStrings[1].trim().substring(0, btnStrings[1].trim().indexOf("("));
                    String btnprop = btnStrings[1].trim().substring(btnStrings[1].trim().indexOf("(") + 1,
                            btnStrings[1].trim().indexOf("%"));

                    Lb2Count = Integer.valueOf(btnCount);
                    Lb2Prop = Double.valueOf(btnprop);
                    if (Constant.sum < limit) {
                        String oldTxt = btnLbl + "=" + Lb2Count + "(" + String.format("%.2f", Lb2Prop) + "%"
                                + ")";
                        morphologyCounts.remove(oldTxt);
                        Lb2Count = Lb2Count + 1;
                        Constant.sum = Constant.sum + 1;
                        Lb2Prop = (Lb2Count * 100.0) / Constant.sum;
                        String newTxt = btnLbl + ":" + Lb2Count + "(" + String.format("%.2f", Lb2Prop) + "%"
                                + ")";
                        btn2.setText(newTxt);
                        newTxt = btnLbl + "=" + Lb2Count + "(" + String.format("%.2f", Lb2Prop) + "%" + ")";
                        morphologyCounts.add(newTxt);
                    } else if (Constant.sum == limit) {
                        limitRchdSound.start();
                        Constant.sum++;
                    }

                    if (Constant.sum < limit)
                        tv.setText("Total Count:" + Constant.sum);
                    else
                        tv.setText("Total Count:" + limit);
                } catch (Exception e) {
                    e.printStackTrace();
                    Toast.makeText(getApplicationContext(), "Error occured. Restart and try again",
                            Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
    if (btn3 != null) {
        btn3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (currentButton == null)
                    currentButton = "btn3";
                else {
                    if (!"btn3".equalsIgnoreCase(currentButton)) {
                        //make sound
                        btnChangeSound.start();
                        currentButton = "btn3";
                    }
                }

                try {
                    String[] btnStrings = btn3.getText().toString().trim().split(":");
                    String btnLbl = btnStrings[0].trim();
                    String btnCount = btnStrings[1].trim().substring(0, btnStrings[1].trim().indexOf("("));
                    String btnprop = btnStrings[1].trim().substring(btnStrings[1].trim().indexOf("(") + 1,
                            btnStrings[1].trim().indexOf("%"));

                    Lb3Count = Integer.valueOf(btnCount);
                    Lb3Prop = Double.valueOf(btnprop);
                    if (Constant.sum < limit) {
                        String oldTxt = btnLbl + "=" + Lb3Count + "(" + String.format("%.2f", Lb3Prop) + "%"
                                + ")";
                        morphologyCounts.remove(oldTxt);
                        Lb3Count = Lb3Count + 1;
                        Constant.sum = Constant.sum + 1;
                        Lb3Prop = (Lb3Count * 100.0) / Constant.sum;
                        String newTxt = btnLbl + ":" + Lb3Count + "(" + String.format("%.2f", Lb3Prop) + "%"
                                + ")";
                        btn3.setText(newTxt);
                        newTxt = btnLbl + "=" + Lb3Count + "(" + String.format("%.2f", Lb3Prop) + "%" + ")";
                        morphologyCounts.add(newTxt);
                    } else if (Constant.sum == limit) {
                        limitRchdSound.start();
                        Constant.sum++;
                    }

                    if (Constant.sum < limit)
                        tv.setText("Total Count:" + Constant.sum);
                    else
                        tv.setText("Total Count:" + limit);
                } catch (Exception e) {
                    e.printStackTrace();
                    Toast.makeText(getApplicationContext(), "Error occured. Restart and try again",
                            Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
    if (btn4 != null) {
        btn4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (currentButton == null)
                    currentButton = "btn4";
                else {
                    if (!"btn4".equalsIgnoreCase(currentButton)) {
                        //make sound
                        btnChangeSound.start();
                        currentButton = "btn4";
                    }
                }

                try {
                    String[] btnStrings = btn4.getText().toString().trim().split(":");
                    String btnLbl = btnStrings[0].trim();
                    String btnCount = btnStrings[1].trim().substring(0, btnStrings[1].trim().indexOf("("));
                    String btnprop = btnStrings[1].trim().substring(btnStrings[1].trim().indexOf("(") + 1,
                            btnStrings[1].trim().indexOf("%"));

                    Lb4Count = Integer.valueOf(btnCount);
                    Lb4Prop = Double.valueOf(btnprop);
                    if (Constant.sum < limit) {
                        String oldTxt = btnLbl + "=" + Lb4Count + "(" + String.format("%.2f", Lb4Prop) + "%"
                                + ")";
                        morphologyCounts.remove(oldTxt);
                        Lb4Count = Lb4Count + 1;
                        Constant.sum = Constant.sum + 1;
                        Lb4Prop = (Lb4Count * 100.0) / Constant.sum;
                        String newTxt = btnLbl + ":" + Lb4Count + "(" + String.format("%.2f", Lb4Prop) + "%"
                                + ")";
                        btn4.setText(newTxt);
                        newTxt = btnLbl + "=" + Lb4Count + "(" + String.format("%.2f", Lb4Prop) + "%" + ")";
                        morphologyCounts.add(newTxt);
                    } else if (Constant.sum == limit) {
                        limitRchdSound.start();
                        Constant.sum++;
                    }

                    if (Constant.sum < limit)
                        tv.setText("Total Count:" + Constant.sum);
                    else
                        tv.setText("Total Count:" + limit);
                } catch (Exception e) {
                    e.printStackTrace();
                    Toast.makeText(getApplicationContext(), "Error occured. Restart and try again",
                            Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
    if (btn5 != null) {
        btn5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (currentButton == null)
                    currentButton = "btn5";
                else {
                    if (!"btn5".equalsIgnoreCase(currentButton)) {
                        //make sound
                        btnChangeSound.start();
                        currentButton = "btn5";
                    }
                }

                try {
                    String[] btnStrings = btn5.getText().toString().trim().split(":");
                    String btnLbl = btnStrings[0].trim();
                    String btnCount = btnStrings[1].trim().substring(0, btnStrings[1].trim().indexOf("("));
                    String btnprop = btnStrings[1].trim().substring(btnStrings[1].trim().indexOf("(") + 1,
                            btnStrings[1].trim().indexOf("%"));

                    Lb5Count = Integer.valueOf(btnCount);
                    Lb5Prop = Double.valueOf(btnprop);
                    if (Constant.sum < limit) {
                        String oldTxt = btnLbl + "=" + Lb5Count + "(" + String.format("%.2f", Lb5Prop) + "%"
                                + ")";
                        morphologyCounts.remove(oldTxt);
                        Lb5Count = Lb5Count + 1;
                        Constant.sum = Constant.sum + 1;
                        Lb5Prop = (Lb5Count * 100.0) / Constant.sum;
                        String newTxt = btnLbl + ":" + Lb5Count + "(" + String.format("%.2f", Lb5Prop) + "%"
                                + ")";
                        btn5.setText(newTxt);
                        newTxt = btnLbl + "=" + Lb5Count + "(" + String.format("%.2f", Lb5Prop) + "%" + ")";
                        morphologyCounts.add(newTxt);
                    } else if (Constant.sum == limit) {
                        limitRchdSound.start();
                        Constant.sum++;
                    }

                    if (Constant.sum < limit)
                        tv.setText("Total Count:" + Constant.sum);
                    else
                        tv.setText("Total Count:" + limit);
                } catch (Exception e) {
                    e.printStackTrace();
                    Toast.makeText(getApplicationContext(), "Error occured. Restart and try again",
                            Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
    if (btn6 != null) {
        btn6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (currentButton == null)
                    currentButton = "btn6";
                else {
                    if (!"btn6".equalsIgnoreCase(currentButton)) {
                        //make sound
                        btnChangeSound.start();
                        currentButton = "btn6";
                    }
                }

                try {
                    String[] btnStrings = btn6.getText().toString().trim().split(":");
                    String btnLbl = btnStrings[0].trim();
                    String btnCount = btnStrings[1].trim().substring(0, btnStrings[1].trim().indexOf("("));
                    String btnprop = btnStrings[1].trim().substring(btnStrings[1].trim().indexOf("(") + 1,
                            btnStrings[1].trim().indexOf("%"));

                    Lb6Count = Integer.valueOf(btnCount);
                    Lb6Prop = Double.valueOf(btnprop);
                    if (Constant.sum < limit) {
                        String oldTxt = btnLbl + "=" + Lb6Count + "(" + String.format("%.2f", Lb6Prop) + "%"
                                + ")";
                        morphologyCounts.remove(oldTxt);
                        Lb6Count = Lb6Count + 1;
                        Constant.sum = Constant.sum + 1;
                        Lb6Prop = (Lb6Count * 100.0) / Constant.sum;
                        String newTxt = btnLbl + ":" + Lb6Count + "(" + String.format("%.2f", Lb6Prop) + "%"
                                + ")";
                        btn6.setText(newTxt);
                        newTxt = btnLbl + "=" + Lb6Count + "(" + String.format("%.2f", Lb6Prop) + "%" + ")";
                        morphologyCounts.add(newTxt);
                    } else if (Constant.sum == limit) {
                        limitRchdSound.start();
                        Constant.sum++;
                    }

                    if (Constant.sum < limit)
                        tv.setText("Total Count:" + Constant.sum);
                    else
                        tv.setText("Total Count:" + limit);
                } catch (Exception e) {
                    e.printStackTrace();
                    Toast.makeText(getApplicationContext(), "Error occured. Restart and try again",
                            Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
    if (btn7 != null) {
        btn7.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (currentButton == null)
                    currentButton = "btn7";
                else {
                    if (!"btn7".equalsIgnoreCase(currentButton)) {
                        //make sound
                        btnChangeSound.start();
                        currentButton = "btn7";
                    }
                }

                try {
                    String[] btnStrings = btn7.getText().toString().trim().split(":");
                    String btnLbl = btnStrings[0].trim();
                    String btnCount = btnStrings[1].trim().substring(0, btnStrings[1].trim().indexOf("("));
                    String btnprop = btnStrings[1].trim().substring(btnStrings[1].trim().indexOf("(") + 1,
                            btnStrings[1].trim().indexOf("%"));

                    Lb7Count = Integer.valueOf(btnCount);
                    Lb7Prop = Double.valueOf(btnprop);
                    if (Constant.sum < limit) {
                        String oldTxt = btnLbl + "=" + Lb7Count + "(" + String.format("%.2f", Lb7Prop) + "%"
                                + ")";
                        morphologyCounts.remove(oldTxt);
                        Lb7Count = Lb7Count + 1;
                        Constant.sum = Constant.sum + 1;
                        Lb7Prop = (Lb7Count * 100.0) / Constant.sum;
                        String newTxt = btnLbl + ":" + Lb7Count + "(" + String.format("%.2f", Lb7Prop) + "%"
                                + ")";
                        btn7.setText(newTxt);
                        newTxt = btnLbl + "=" + Lb7Count + "(" + String.format("%.2f", Lb7Prop) + "%" + ")";
                        morphologyCounts.add(newTxt);
                    } else if (Constant.sum == limit) {
                        limitRchdSound.start();
                        Constant.sum++;
                    }

                    if (Constant.sum < limit)
                        tv.setText("Total Count:" + Constant.sum);
                    else
                        tv.setText("Total Count:" + limit);
                } catch (Exception e) {
                    e.printStackTrace();
                    Toast.makeText(getApplicationContext(), "Error occured. Restart and try again",
                            Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
    if (btn8 != null) {
        btn8.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (currentButton == null)
                    currentButton = "btn8";
                else {
                    if (!"btn8".equalsIgnoreCase(currentButton)) {
                        //make sound
                        btnChangeSound.start();
                        currentButton = "btn8";
                    }
                }

                try {
                    String[] btnStrings = btn8.getText().toString().trim().split(":");
                    String btnLbl = btnStrings[0].trim();
                    String btnCount = btnStrings[1].trim().substring(0, btnStrings[1].trim().indexOf("("));
                    String btnprop = btnStrings[1].trim().substring(btnStrings[1].trim().indexOf("(") + 1,
                            btnStrings[1].trim().indexOf("%"));

                    Lb8Count = Integer.valueOf(btnCount);
                    Lb8Prop = Double.valueOf(btnprop);
                    if (Constant.sum < limit) {
                        String oldTxt = btnLbl + "=" + Lb8Count + "(" + String.format("%.2f", Lb8Prop) + "%"
                                + ")";
                        morphologyCounts.remove(oldTxt);
                        Lb8Count = Lb8Count + 1;
                        Constant.sum = Constant.sum + 1;
                        Lb8Prop = (Lb8Count * 100.0) / Constant.sum;
                        String newTxt = btnLbl + ":" + Lb8Count + "(" + String.format("%.2f", Lb8Prop) + "%"
                                + ")";
                        btn8.setText(newTxt);
                        newTxt = btnLbl + "=" + Lb8Count + "(" + String.format("%.2f", Lb8Prop) + "%" + ")";
                        morphologyCounts.add(newTxt);
                    } else if (Constant.sum == limit) {
                        limitRchdSound.start();
                        Constant.sum++;
                    }

                    if (Constant.sum < limit)
                        tv.setText("Total Count:" + Constant.sum);
                    else
                        tv.setText("Total Count:" + limit);
                } catch (Exception e) {
                    e.printStackTrace();
                    Toast.makeText(getApplicationContext(), "Error occured. Restart and try again",
                            Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

}

From source file:cl.ipp.katbag.fragment.PlayerBook.java

public void playSound(String identifier) {
    if (!identifier.contentEquals("")) {
        int sound = mainActivity.getResources().getIdentifier(identifier, "raw", mainActivity.getPackageName());
        stopPlayer();// www .  j  av  a2  s.c  om
        mPlayer = MediaPlayer.create(mainActivity.context, sound);
        mPlayer.start();
    }
}

From source file:com.zuluindia.watchpresenter.MonitorVolumeKeyPress.java

public void onCreate() {
    super.onCreate();
    settings = getSharedPreferences(Constants.SETTINGS_NAME, MODE_PRIVATE);
    vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    Log.d(LOGCAT, "Service Started!");
    objPlayer = MediaPlayer.create(this, com.zuluindia.watchpresenter.R.raw.silence);
    objPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
    objPlayer.setLooping(true);/*from  w  ww.  ja  v  a 2 s  .c o  m*/
    timer = new Timer();
    audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    midVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC) / 2;
    resetVolume();
}

From source file:org.openbell.sdk.MyFirebaseMessagingService.java

private void sendNotification(String notificationTitle, String notificationContent, int notificationMessageID) {
    if (BuildConfig.DEBUG)
        Log.d(LOG_TAG, "sendNotification()");

    Intent mIntent = new Intent(this, ActivityMain.class);
    mIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, mIntent,
            PendingIntent.FLAG_ONE_SHOT);

    int mediaResource = PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
            .getString("preference_notification", "bell_default").equals("bell_default") ? R.raw.bell_default
                    : R.raw.bell_trump;//from  w  ww.  j a  va  2s .  c  o m
    mediaPlayer = MediaPlayer.create(this, mediaResource);
    mediaPlayer.start();

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
    notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
    notificationBuilder.setContentTitle(notificationTitle);
    notificationBuilder.setContentText(notificationContent);
    notificationBuilder.setSubText(getString(R.string.app_name));
    notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(notificationContent));
    notificationBuilder.setVibrate(new long[] { 0, 1000, 250, 1000, 250, 1000, 250, 150, 50, 150, 50, 150, 50,
            150, 50, 150, 50, 150, 50, 150 });
    notificationBuilder.setAutoCancel(false);
    notificationBuilder.setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.notify(notificationMessageID, notificationBuilder.build());
}

From source file:com.cw.litenote.note.AudioUi_note.java

public static void initAudioProgress(AppCompatActivity act, String audioUriInDB, ViewPager _pager) {
    SeekBar seekBar = (SeekBar) act.findViewById(R.id.pager_img_audio_seek_bar);
    ImageView mPager_audio_play_button = (ImageView) act.findViewById(R.id.pager_btn_audio_play);

    // set audio block listeners
    setAudioBlockListener(act, audioUriInDB, _pager);

    mProgress = 0;/*from   w  w w.  jav  a  2  s.c  om*/

    mAudioUriInDB = audioUriInDB;
    showAudioName(act);

    TextView audioTitle = (TextView) act.findViewById(R.id.pager_audio_title);
    audioTitle.setSelected(false);
    mPager_audio_play_button.setImageResource(R.drawable.ic_media_play);
    audioTitle.setTextColor(ColorSet.getPauseColor(act));
    audioTitle.setSelected(false);

    // current position
    int curHour = Math.round((float) (mProgress / 1000 / 60 / 60));
    int curMin = Math.round((float) ((mProgress - curHour * 60 * 60 * 1000) / 1000 / 60));
    int curSec = Math.round((float) ((mProgress - curHour * 60 * 60 * 1000 - curMin * 60 * 1000) / 1000));
    String curr_pos_str = String.format(Locale.ENGLISH, "%2d", curHour) + ":"
            + String.format(Locale.ENGLISH, "%02d", curMin) + ":"
            + String.format(Locale.ENGLISH, "%02d", curSec);

    TextView audio_curr_pos = (TextView) act.findViewById(R.id.pager_audio_current_pos);
    audio_curr_pos.setText(curr_pos_str);
    audio_curr_pos.setTextColor(ColorSet.color_white);

    // audio seek bar
    seekBar.setProgress(mProgress); // This math construction give a percentage of "was playing"/"song length"
    seekBar.setMax(99); // It means 100% .0-99
    seekBar.setVisibility(View.VISIBLE);

    // get audio file length
    try {
        if (Util.isUriExisted(mAudioUriInDB, act)) {
            MediaPlayer mp = MediaPlayer.create(act, Uri.parse(mAudioUriInDB));
            mediaFileLength = mp.getDuration();
            mp.release();
        }
    } catch (Exception e) {
        System.out.println("AudioUi_note / _initAudioProgress / exception");
    }
    // set audio file length
    int fileHour = Math.round((float) (mediaFileLength / 1000 / 60 / 60));
    int fileMin = Math.round((float) ((mediaFileLength - fileHour * 60 * 60 * 1000) / 1000 / 60));
    int fileSec = Math
            .round((float) ((mediaFileLength - fileHour * 60 * 60 * 1000 - fileMin * 1000 * 60) / 1000));

    String strHour = String.format(Locale.ENGLISH, "%2d", fileHour);
    String strMinute = String.format(Locale.ENGLISH, "%02d", fileMin);
    String strSecond = String.format(Locale.ENGLISH, "%02d", fileSec);
    String strLength = strHour + ":" + strMinute + ":" + strSecond;

    TextView audio_length = (TextView) act.findViewById(R.id.pager_audio_file_length);
    audio_length.setText(strLength);
    audio_length.setTextColor(ColorSet.color_white);
}