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:com.example.volunteerhandbook.MainActivity.java

private void startSpeaker() {
    if (mSpeaker != null)
        return;//  w  w w  .  j a  va2 s  . c o m
    //if (!firstTime) return;
    mSpeaker = MediaPlayer.create(this, R.raw.kp_grateful);
    mSpeaker.setOnCompletionListener(this);
    mSpeaker.start();
}

From source file:com.insthub.O2OMobile.Activity.C1_PublishOrderActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.c1_publish_order);
    mFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    File file = new File(newFileName());
    if (file.exists()) {
        file.delete();/*from w  w w.  ja  v a 2s  .  c  om*/
    }

    Intent intent = getIntent();
    mServiceType = (SERVICE_TYPE) intent.getSerializableExtra(O2OMobileAppConst.SERVICE_TYPE);
    mDefaultReceiverId = intent.getIntExtra(DEFAULT_RECEIVER_ID, 0);
    service_list = intent.getStringExtra("service_list");

    mBack = (ImageView) findViewById(R.id.top_view_back);
    mTitle = (TextView) findViewById(R.id.top_view_title);
    mBack.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            finish();
        }
    });
    mArrowImage = (ImageView) findViewById(R.id.top_view_arrow_image);
    mClose = (ImageView) findViewById(R.id.top_view_right_close);
    mTitleView = (LinearLayout) findViewById(R.id.top_view_title_view);
    mServiceTypeView = (FrameLayout) findViewById(R.id.c1_publish_order_service_type_view);
    mServiceTypeListview = (ListView) findViewById(R.id.c1_publish_order_service_type_list);
    mPrice = (EditText) findViewById(R.id.c1_publish_order_price);
    mTime = (TextView) findViewById(R.id.c1_publish_order_time);
    mLocation = (EditText) findViewById(R.id.c1_publish_order_location);
    mText = (EditText) findViewById(R.id.c1_publish_order_text);
    mVoice = (Button) findViewById(R.id.c1_publish_order_voice);
    mVoicePlay = (Button) findViewById(R.id.c1_publish_order_voicePlay);
    mVoiceReset = (ImageView) findViewById(R.id.c1_publish_order_voiceReset);
    mPublish = (Button) findViewById(R.id.c1_publish_order_publish);
    mVoiceView = (FrameLayout) findViewById(R.id.c1_publish_order_voice_view);
    mVoiceAnim = (ImageView) findViewById(R.id.c1_publish_order_voice_anim);
    mVoiceAnim.setImageResource(R.anim.voice_animation);
    mAnimationDrawable = (AnimationDrawable) mVoiceAnim.getDrawable();
    mAnimationDrawable.setOneShot(false);
    mTitleView.setEnabled(false);
    mServiceTypeView.setOnClickListener(null);
    mServiceTypeListview.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // TODO Auto-generated method stub
            if (mDefaultReceiverId == 0) {
                mTitle.setText(mHomeModel.publicServiceTypeList.get(position).title);
                mServiceTypeId = mHomeModel.publicServiceTypeList.get(position).id;
                mC1PublishOrderAdapter = new C1_PublishOrderAdapter(C1_PublishOrderActivity.this,
                        mHomeModel.publicServiceTypeList, position);
                mServiceTypeListview.setAdapter(mC1PublishOrderAdapter);
                mClose.setVisibility(View.GONE);
                mArrowImage.setImageResource(R.drawable.b3_arrow_down);
                AnimationUtil.backAnimationFromBottom(mServiceTypeListview);
                Handler mHandler = new Handler() {
                    @Override
                    public void handleMessage(Message msg) {
                        super.handleMessage(msg);
                        mServiceTypeView.setVisibility(View.GONE);
                    }
                };
                mHandler.sendEmptyMessageDelayed(0, 200);
            } else {
                mTitle.setText(mServiceTypeList.get(position).title);
                mServiceTypeId = mServiceTypeList.get(position).id;
                mC1PublishOrderAdapter = new C1_PublishOrderAdapter(C1_PublishOrderActivity.this,
                        mServiceTypeList, position);
                mServiceTypeListview.setAdapter(mC1PublishOrderAdapter);
                mClose.setVisibility(View.GONE);
                mArrowImage.setImageResource(R.drawable.b3_arrow_down);
                AnimationUtil.backAnimationFromBottom(mServiceTypeListview);
                Handler mHandler = new Handler() {
                    @Override
                    public void handleMessage(Message msg) {
                        super.handleMessage(msg);
                        mServiceTypeView.setVisibility(View.GONE);
                    }
                };
                mHandler.sendEmptyMessageDelayed(0, 200);
            }

        }
    });

    mTitleView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            if (mServiceTypeView.getVisibility() == View.GONE) {
                mServiceTypeView.setVisibility(View.VISIBLE);
                mClose.setVisibility(View.VISIBLE);
                mArrowImage.setImageResource(R.drawable.b4_arrow_up);
                AnimationUtil.showAnimationFromTop(mServiceTypeListview);
                closeKeyBoard();
            } else {
                mClose.setVisibility(View.GONE);
                mArrowImage.setImageResource(R.drawable.b3_arrow_down);
                AnimationUtil.backAnimationFromBottom(mServiceTypeListview);
                Handler mHandler = new Handler() {
                    @Override
                    public void handleMessage(Message msg) {
                        super.handleMessage(msg);
                        mServiceTypeView.setVisibility(View.GONE);
                    }
                };
                mHandler.sendEmptyMessageDelayed(0, 200);
            }
        }
    });

    mClose.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            mClose.setVisibility(View.GONE);
            mArrowImage.setImageResource(R.drawable.b3_arrow_down);
            AnimationUtil.backAnimationFromBottom(mServiceTypeListview);
            Handler mHandler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    super.handleMessage(msg);
                    mServiceTypeView.setVisibility(View.GONE);
                }
            };
            mHandler.sendEmptyMessageDelayed(0, 200);
        }
    });

    mPrice.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub
            if (s.toString().length() > 0) {
                if (s.toString().substring(0, 1).equals(".")) {
                    s = s.toString().substring(1, s.length());
                    mPrice.setText(s);
                }
            }
            if (s.toString().length() > 1) {
                if (s.toString().substring(0, 1).equals("0")) {
                    if (!s.toString().substring(1, 2).equals(".")) {
                        s = s.toString().substring(1, s.length());
                        mPrice.setText(s);
                        CharSequence charSequencePirce = mPrice.getText();
                        if (charSequencePirce instanceof Spannable) {
                            Spannable spanText = (Spannable) charSequencePirce;
                            Selection.setSelection(spanText, charSequencePirce.length());
                        }
                    }
                }
            }
            boolean flag = false;
            for (int i = 0; i < s.toString().length() - 1; i++) {
                String getstr = s.toString().substring(i, i + 1);
                if (getstr.equals(".")) {
                    flag = true;
                    break;
                }
            }
            if (flag) {
                int i = s.toString().indexOf(".");
                if (s.toString().length() - 3 > i) {
                    String getstr = s.toString().substring(0, i + 3);
                    mPrice.setText(getstr);
                    CharSequence charSequencePirce = mPrice.getText();
                    if (charSequencePirce instanceof Spannable) {
                        Spannable spanText = (Spannable) charSequencePirce;
                        Selection.setSelection(spanText, charSequencePirce.length());
                    }
                }
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // TODO Auto-generated method stub
        }

        @Override
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub
        }
    });

    initData();

    mHomeModel = new HomeModel(this);
    mHomeModel.addResponseListener(this);
    if (mDefaultReceiverId == 0) {
        mShared = getSharedPreferences(O2OMobileAppConst.USERINFO, 0);
        mHomeData = mShared.getString("home_data", "");
        if ("".equals(mHomeData)) {
            mHomeModel.getServiceTypeList();
        } else {
            try {
                servicetypelistResponse response = new servicetypelistResponse();
                response.fromJson(new JSONObject(mHomeData));
                mHomeModel.publicServiceTypeList = response.services;
                setServiceTypeAdater();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    } else {
        if (service_list != null && !"".equals(service_list)) {
            try {
                JSONObject userJson = new JSONObject(service_list);
                myservicelistResponse response = new myservicelistResponse();
                response.fromJson(userJson);
                for (int i = 0; i < response.services.size(); i++) {
                    SERVICE_TYPE service = new SERVICE_TYPE();
                    service = response.services.get(i).service_type;
                    mServiceTypeList.add(service);
                }
                if (mServiceTypeList.size() > 0) {
                    mTitleView.setEnabled(true);
                    mArrowImage.setVisibility(View.VISIBLE);
                    if (mServiceType != null) {
                        for (int i = 0; i < mServiceTypeList.size(); i++) {
                            if (mServiceType.id == mServiceTypeList.get(i).id) {
                                mC1PublishOrderAdapter = new C1_PublishOrderAdapter(this, mServiceTypeList, i);
                                mServiceTypeListview.setAdapter(mC1PublishOrderAdapter);
                                mTitle.setText(mServiceTypeList.get(i).title);
                                mServiceTypeId = mServiceTypeList.get(i).id;
                                break;
                            }
                        }
                    } else {
                        mC1PublishOrderAdapter = new C1_PublishOrderAdapter(this, mServiceTypeList);
                        mServiceTypeListview.setAdapter(mC1PublishOrderAdapter);
                        mTitle.setText(getString(R.string.select_service));
                    }

                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } else {
            mShared = getSharedPreferences(O2OMobileAppConst.USERINFO, 0);
            mHomeData = mShared.getString("home_data", "");
            if ("".equals(mHomeData)) {
                mHomeModel.getServiceTypeList();
            } else {
                try {
                    servicetypelistResponse response = new servicetypelistResponse();
                    response.fromJson(new JSONObject(mHomeData));
                    mHomeModel.publicServiceTypeList = response.services;
                    setServiceTypeAdater();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    mLocationInfoModel = new LocationInfoModel(this);
    mLocationInfoModel.addResponseListener(this);
    mLocationInfoModel.get();

    mOrderPublishModel = new OrderPublishModel(this);
    mOrderPublishModel.addResponseListener(this);

    //??
    CharSequence charSequencePirce = mPrice.getText();
    if (charSequencePirce instanceof Spannable) {
        Spannable spanText = (Spannable) charSequencePirce;
        Selection.setSelection(spanText, charSequencePirce.length());
    }
    CharSequence charSequenceLocation = mLocation.getText();
    if (charSequenceLocation instanceof Spannable) {
        Spannable spanText = (Spannable) charSequenceLocation;
        Selection.setSelection(spanText, charSequenceLocation.length());
    }

    mVoice.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                closeKeyBoard();
                mVoice.setKeepScreenOn(true);
                mMaxTime = MAX_TIME;
                mVoiceView.setVisibility(View.VISIBLE);
                mAnimationDrawable.start();
                startRecording();
            } else if (event.getAction() == MotionEvent.ACTION_UP) {
                mVoice.setKeepScreenOn(false);
                mVoiceView.setVisibility(View.GONE);
                mAnimationDrawable.stop();
                if (mMaxTime > 28) {
                    mVoice.setEnabled(false);
                    Handler mHandler = new Handler() {
                        @Override
                        public void handleMessage(Message msg) {
                            super.handleMessage(msg);
                            stopRecording();
                            mVoice.setEnabled(true);
                        }
                    };
                    mHandler.sendEmptyMessageDelayed(0, 500);
                } else {
                    stopRecording();
                }
            } else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
                mVoice.setKeepScreenOn(false);
                mVoiceView.setVisibility(View.GONE);
                mAnimationDrawable.stop();
                if (mMaxTime > 28) {
                    mVoice.setEnabled(false);
                    Handler mHandler = new Handler() {
                        @Override
                        public void handleMessage(Message msg) {
                            super.handleMessage(msg);
                            stopRecording();
                            mVoice.setEnabled(true);
                        }
                    };
                    mHandler.sendEmptyMessageDelayed(0, 500);
                } else {
                    stopRecording();
                }
            } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
                mVoice.getParent().requestDisallowInterceptTouchEvent(true);
            }
            return false;
        }
    });

    mVoicePlay.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if (mPlayer == null) {
                File file = new File(mFileName);
                if (file.exists()) {
                    mPlayer = new MediaPlayer();
                    mVoicePlay.setBackgroundResource(R.anim.record_animation);
                    mAnimationDrawable2 = (AnimationDrawable) mVoicePlay.getBackground();
                    mAnimationDrawable2.setOneShot(false);
                    mAnimationDrawable2.start();
                    try {
                        mPlayer.setDataSource(mFileName);
                        mPlayer.prepare();
                        mPlayer.start();
                        mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                            @Override
                            public void onCompletion(MediaPlayer mp) {
                                mp.reset();
                                mPlayer = null;
                                mVoicePlay.setBackgroundResource(R.drawable.b5_play_btn);
                                mAnimationDrawable2.stop();
                            }
                        });
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                } else {
                    Toast.makeText(C1_PublishOrderActivity.this, getString(R.string.file_does_not_exist),
                            Toast.LENGTH_SHORT).show();
                }
            } else {
                mPlayer.release();
                mPlayer = null;
                mVoicePlay.setBackgroundResource(R.drawable.b5_play_btn);
                mAnimationDrawable2.stop();
            }
        }
    });

    mVoiceReset.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if (mPlayer != null) {
                mPlayer.release();
                mPlayer = null;
                mVoicePlay.setBackgroundResource(R.drawable.b5_play_btn);
                mAnimationDrawable2.stop();
            }
            File file = new File(mFileName);
            if (file.exists()) {
                file.delete();
            }
            mVoice.setVisibility(View.VISIBLE);
            mVoicePlay.setVisibility(View.GONE);
            mVoiceReset.setVisibility(View.GONE);
        }
    });

    mPublish.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            File file = new File(newFileName());
            int duration = 0;
            if (file.exists()) {
                MediaPlayer mp = MediaPlayer.create(C1_PublishOrderActivity.this, Uri.parse(mFileName));
                if (null != mp) {
                    duration = mp.getDuration();//? ms
                    mp.release();
                }
                if (duration % 1000 > 500) {
                    duration = duration / 1000 + 1;
                } else {
                    duration = duration / 1000;
                }
            } else {
                file = null;
            }
            int num = 0;
            try { // ??
                Date date = new Date();
                Date date1 = mFormat.parse(mFormat.format(date));
                Date date2 = mFormat.parse(mTime.getText().toString());
                num = date2.compareTo(date1);

                if (num < 0) {
                    long diff = date1.getTime() - date2.getTime();
                    long mins = diff / (1000 * 60);
                    if (mins < 3) {
                        num = 1;
                    }
                }
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            if (mServiceTypeId == 0) {
                ToastView toast = new ToastView(C1_PublishOrderActivity.this,
                        getString(R.string.select_service));
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            } else if (mPrice.getText().toString().equals("")) {
                ToastView toast = new ToastView(C1_PublishOrderActivity.this, getString(R.string.price_range));
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            } else if (mPrice.getText().toString().equals("0.")) {
                ToastView toast = new ToastView(C1_PublishOrderActivity.this, getString(R.string.right_price));
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            } else if (mTime.getText().toString().equals("")) {
                ToastView toast = new ToastView(C1_PublishOrderActivity.this, getString(R.string.appoint_time));
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            } else if (num < 0) {
                ToastView toast = new ToastView(C1_PublishOrderActivity.this,
                        getString(R.string.wrong_appoint_time_hint));
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            } else if (mLocation.getText().toString().equals("")) {
                ToastView toast = new ToastView(C1_PublishOrderActivity.this,
                        getString(R.string.appoint_location_hint));
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            } else {
                mOrderPublishModel.publish(mPrice.getText().toString(), mTime.getText().toString(),
                        mLocation.getText().toString(), mText.getText().toString(), file, mServiceTypeId,
                        mDefaultReceiverId, duration);
            }
        }
    });
}

From source file:ee.ioc.phon.android.speak.RecognizerIntentActivity.java

private boolean playSound(int sound) {
    if (mPrefs.getBoolean(mRes.getString(R.string.keyAudioCues), mRes.getBoolean(R.bool.defaultAudioCues))) {
        mMediaPlayer = MediaPlayer.create(this, sound);
        mMediaPlayer.start();//from   w ww.j  a  v a 2 s . c om
        return true;
    }
    return false;
}

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

public void playSound(String identifier) {
    Log.d("ply", "playSound - identifier");

    int sound = mainActivity.getResources().getIdentifier(identifier, "raw", mainActivity.getPackageName());
    stopPlayer();//w ww  .  j av a 2 s.co m

    if (!muteAll) {
        mPlayer = MediaPlayer.create(mainActivity.context, sound);
        mPlayer.start();
    }
}

From source file:foam.mongoose.StarwispBuilder.java

public void Update(final StarwispActivity ctx, final String ctxname, JSONArray arr) {
    try {//  w  w w  . java 2 s  . co m

        String type = arr.getString(0);
        final Integer id = arr.getInt(1);
        String token = arr.getString(2);

        //Log.i("starwisp", "Update: "+type+" "+id+" "+token);

        // non widget commands
        if (token.equals("toast")) {
            Toast msg = Toast.makeText(ctx.getBaseContext(), arr.getString(3), Toast.LENGTH_SHORT);
            msg.show();
            return;
        }

        if (token.equals("play-sound")) {
            String name = arr.getString(3);

            if (name.equals("ping")) {
                MediaPlayer mp = MediaPlayer.create(ctx, R.raw.ping);
                mp.start();
            }
            if (name.equals("active")) {
                MediaPlayer mp = MediaPlayer.create(ctx, R.raw.active);
                mp.start();
            }
        }

        if (token.equals("vibrate")) {
            Vibrator v = (Vibrator) ctx.getSystemService(Context.VIBRATOR_SERVICE);
            v.vibrate(arr.getInt(3));
        }

        if (type.equals("replace-fragment")) {
            int ID = arr.getInt(1);
            String name = arr.getString(2);
            Fragment fragment = ActivityManager.GetFragment(name);
            FragmentTransaction ft = ctx.getSupportFragmentManager().beginTransaction();

            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);

            //ft.setCustomAnimations(
            //    R.animator.card_flip_right_in, R.animator.card_flip_right_out,
            //    R.animator.card_flip_left_in, R.animator.card_flip_left_out);
            ft.replace(ID, fragment);
            //ft.addToBackStack(null);
            ft.commit();
            return;
        }

        if (token.equals("dialog-fragment")) {
            FragmentManager fm = ctx.getSupportFragmentManager();
            final int ID = arr.getInt(3);
            final JSONArray lp = arr.getJSONArray(4);
            final String name = arr.getString(5);

            final Dialog dialog = new Dialog(ctx);
            dialog.setTitle("Title...");

            LinearLayout inner = new LinearLayout(ctx);
            inner.setId(ID);
            inner.setLayoutParams(BuildLayoutParams(lp));

            dialog.setContentView(inner);

            //                Fragment fragment = ActivityManager.GetFragment(name);
            //                FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction();
            //                fragmentTransaction.add(ID,fragment);
            //                fragmentTransaction.commit();

            dialog.show();

            /*                DialogFragment df = new DialogFragment() {
            @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                     Bundle savedInstanceState) {
                LinearLayout inner = new LinearLayout(ctx);
                inner.setId(ID);
                inner.setLayoutParams(BuildLayoutParams(lp));
                    
                return inner;
            }
                    
            @Override
            public Dialog onCreateDialog(Bundle savedInstanceState) {
                Dialog ret = super.onCreateDialog(savedInstanceState);
                Log.i("starwisp","MAKINGDAMNFRAGMENT");
                    
                Fragment fragment = ActivityManager.GetFragment(name);
                FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction();
                fragmentTransaction.add(1,fragment);
                fragmentTransaction.commit();
                return ret;
            }
                            };
                            df.show(ctx.getFragmentManager(), "foo");
            */
        }

        if (token.equals("time-picker-dialog")) {

            final Calendar c = Calendar.getInstance();
            int hour = c.get(Calendar.HOUR_OF_DAY);
            int minute = c.get(Calendar.MINUTE);

            // Create a new instance of TimePickerDialog and return it
            TimePickerDialog d = new TimePickerDialog(ctx, null, hour, minute, true);
            d.show();
            return;
        }
        ;

        if (token.equals("make-directory")) {
            File file = new File(((StarwispActivity) ctx).m_AppDir + arr.getString(3));
            file.mkdirs();
            return;
        }

        if (token.equals("list-files")) {
            final String name = arr.getString(3);
            File file = new File(((StarwispActivity) ctx).m_AppDir + arr.getString(5));
            // todo, should probably call callback with empty list
            if (file != null) {
                File list[] = file.listFiles();

                if (list != null) {
                    String code = "(";
                    for (int i = 0; i < list.length; i++) {
                        code += " \"" + list[i].getName() + "\"";
                    }
                    code += ")";

                    DialogCallback(ctx, ctxname, name, code);
                }
            }
            return;
        }

        if (token.equals("gps-start")) {
            final String name = arr.getString(3);

            if (m_LocationManager == null) {
                m_LocationManager = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE);
                m_GPS = new DorisLocationListener(m_LocationManager);
            }

            m_GPS.Start((StarwispActivity) ctx, name, this);
            return;
        }

        if (token.equals("delayed")) {
            final String name = arr.getString(3);
            final int d = arr.getInt(5);
            Runnable timerThread = new Runnable() {
                public void run() {
                    DialogCallback(ctx, ctxname, name, "");
                }
            };
            m_Handler.removeCallbacksAndMessages(null);
            m_Handler.postDelayed(timerThread, d);
            return;
        }

        if (token.equals("network-connect")) {
            final String name = arr.getString(3);
            final String ssid = arr.getString(5);
            m_NetworkManager.Start(ssid, (StarwispActivity) ctx, name, this);
            return;
        }

        if (token.equals("http-request")) {
            if (m_NetworkManager.state == NetworkManager.State.CONNECTED) {
                Log.i("starwisp", "attempting http request");
                final String name = arr.getString(3);
                final String url = arr.getString(5);
                m_NetworkManager.StartRequestThread(url, "normal", name);
            }
            return;
        }

        if (token.equals("http-download")) {
            if (m_NetworkManager.state == NetworkManager.State.CONNECTED) {
                Log.i("starwisp", "attempting http dl request");
                final String filename = arr.getString(4);
                final String url = arr.getString(5);
                m_NetworkManager.StartRequestThread(url, "download", filename);
            }
            return;
        }

        if (token.equals("send-mail")) {
            final String to[] = new String[1];
            to[0] = arr.getString(3);
            final String subject = arr.getString(4);
            final String body = arr.getString(5);

            JSONArray attach = arr.getJSONArray(6);
            ArrayList<String> paths = new ArrayList<String>();
            for (int a = 0; a < attach.length(); a++) {
                Log.i("starwisp", attach.getString(a));
                paths.add(attach.getString(a));
            }

            email(ctx, to[0], "", subject, body, paths);
        }

        if (token.equals("date-picker-dialog")) {
            final Calendar c = Calendar.getInstance();
            int day = c.get(Calendar.DAY_OF_MONTH);
            int month = c.get(Calendar.MONTH);
            int year = c.get(Calendar.YEAR);

            final String name = arr.getString(3);

            // Create a new instance of TimePickerDialog and return it
            DatePickerDialog d = new DatePickerDialog(ctx, new DatePickerDialog.OnDateSetListener() {
                public void onDateSet(DatePicker view, int year, int month, int day) {
                    DialogCallback(ctx, ctxname, name, day + " " + month + " " + year);
                }
            }, year, month, day);
            d.show();
            return;
        }
        ;

        if (token.equals("alert-dialog")) {

            final String name = arr.getString(3);
            final String msg = arr.getString(5);

            DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    int result = 0;
                    if (which == DialogInterface.BUTTON_POSITIVE)
                        result = 1;
                    DialogCallback(ctx, ctxname, name, "" + result);
                }
            };

            AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
            builder.setMessage(msg).setPositiveButton("Yes", dialogClickListener)
                    .setNegativeButton("No", dialogClickListener).show();

            return;
        }

        if (token.equals("start-activity")) {
            ActivityManager.StartActivity(ctx, arr.getString(3), arr.getInt(4), arr.getString(5));
            return;
        }

        if (token.equals("start-activity-goto")) {
            ActivityManager.StartActivityGoto(ctx, arr.getString(3), arr.getString(4));
            return;
        }

        if (token.equals("finish-activity")) {
            ctx.setResult(arr.getInt(3));
            ctx.finish();
            return;
        }

        ///////////////////////////////////////////////////////////

        // problem associating the id number
        if (id == 0)
            return;

        // now try and find the widget
        View vv = ctx.findViewById(id);
        if (vv == null) {
            Log.i("starwisp", "Can't find widget : " + id);
            return;
        }

        // tokens that work on everything
        if (token.equals("hide")) {
            vv.setVisibility(View.GONE);
            return;
        }

        if (token.equals("show")) {
            vv.setVisibility(View.VISIBLE);
            return;
        }

        // tokens that work on everything
        if (token.equals("set-enabled")) {
            vv.setEnabled(arr.getInt(3) == 1);
            return;
        }

        // special cases
        if (type.equals("linear-layout")) {
            LinearLayout v = (LinearLayout) vv;
            if (token.equals("contents")) {
                v.removeAllViews();
                JSONArray children = arr.getJSONArray(3);
                for (int i = 0; i < children.length(); i++) {
                    Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
                }
            }
        }

        if (type.equals("button-grid")) {
            LinearLayout horiz = (LinearLayout) vv;
            if (token.equals("grid-buttons")) {
                horiz.removeAllViews();

                JSONArray params = arr.getJSONArray(3);
                String buttontype = params.getString(0);
                int height = params.getInt(1);
                int textsize = params.getInt(2);
                LinearLayout.LayoutParams lp = BuildLayoutParams(params.getJSONArray(3));
                final JSONArray buttons = params.getJSONArray(4);
                final int count = buttons.length();
                int vertcount = 0;
                LinearLayout vert = null;

                for (int i = 0; i < count; i++) {
                    JSONArray button = buttons.getJSONArray(i);

                    if (vertcount == 0) {
                        vert = new LinearLayout(ctx);
                        vert.setId(0);
                        vert.setOrientation(LinearLayout.VERTICAL);
                        horiz.addView(vert);
                    }
                    vertcount = (vertcount + 1) % height;

                    if (buttontype.equals("button")) {
                        Button b = new Button(ctx);
                        b.setId(button.getInt(0));
                        b.setText(button.getString(1));
                        b.setTextSize(textsize);
                        b.setLayoutParams(lp);
                        b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                        final String fn = params.getString(5);
                        b.setOnClickListener(new View.OnClickListener() {
                            public void onClick(View v) {
                                CallbackArgs(ctx, ctxname, id, "" + v.getId() + " #t");
                            }
                        });
                        vert.addView(b);
                    } else if (buttontype.equals("toggle")) {
                        ToggleButton b = new ToggleButton(ctx);
                        b.setId(button.getInt(0));
                        b.setText(button.getString(1));
                        b.setTextSize(textsize);
                        b.setLayoutParams(lp);
                        b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                        final String fn = params.getString(5);
                        b.setOnClickListener(new View.OnClickListener() {
                            public void onClick(View v) {
                                String arg = "#f";
                                if (((ToggleButton) v).isChecked())
                                    arg = "#t";
                                CallbackArgs(ctx, ctxname, id, "" + v.getId() + " " + arg);
                            }
                        });
                        vert.addView(b);
                    } else if (buttontype.equals("single")) {
                        ToggleButton b = new ToggleButton(ctx);
                        b.setId(button.getInt(0));
                        b.setText(button.getString(1));
                        b.setTextSize(textsize);
                        b.setLayoutParams(lp);
                        b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                        final String fn = params.getString(5);
                        b.setOnClickListener(new View.OnClickListener() {
                            public void onClick(View v) {
                                try {
                                    for (int i = 0; i < count; i++) {
                                        JSONArray button = buttons.getJSONArray(i);
                                        int bid = button.getInt(0);
                                        if (bid != v.getId()) {
                                            ToggleButton tb = (ToggleButton) ctx.findViewById(bid);
                                            tb.setChecked(false);
                                        }
                                    }
                                } catch (JSONException e) {
                                    Log.e("starwisp", "Error parsing data " + e.toString());
                                }

                                CallbackArgs(ctx, ctxname, id, "" + v.getId() + " #t");
                            }
                        });
                        vert.addView(b);
                    }

                }
            }
        }

        /*
                    if (type.equals("grid-layout")) {
        GridLayout v = (GridLayout)vv;
        if (token.equals("contents")) {
            v.removeAllViews();
            JSONArray children = arr.getJSONArray(3);
            for (int i=0; i<children.length(); i++) {
                Build(ctx,ctxname,new JSONArray(children.getString(i)), v);
            }
        }
                    }
        */
        if (type.equals("view-pager")) {
            ViewPager v = (ViewPager) vv;
            if (token.equals("switch")) {
                v.setCurrentItem(arr.getInt(3));
            }
            if (token.equals("pages")) {
                final JSONArray items = arr.getJSONArray(3);
                v.setAdapter(new FragmentPagerAdapter(ctx.getSupportFragmentManager()) {
                    @Override
                    public int getCount() {
                        return items.length();
                    }

                    @Override
                    public Fragment getItem(int position) {
                        try {
                            String fragname = items.getString(position);
                            return ActivityManager.GetFragment(fragname);
                        } catch (JSONException e) {
                            Log.e("starwisp", "Error parsing data " + e.toString());
                        }
                        return null;
                    }
                });
            }
        }

        if (type.equals("image-view")) {
            ImageView v = (ImageView) vv;
            if (token.equals("image")) {
                int iid = ctx.getResources().getIdentifier(arr.getString(3), "drawable", ctx.getPackageName());
                v.setImageResource(iid);
            }
            if (token.equals("external-image")) {
                Bitmap bitmap = BitmapFactory.decodeFile(arr.getString(3));
                v.setImageBitmap(bitmap);
            }
            return;
        }

        if (type.equals("text-view") || type.equals("debug-text-view")) {
            TextView v = (TextView) vv;
            if (token.equals("text")) {
                if (type.equals("debug-text-view")) {
                    //v.setMovementMethod(new ScrollingMovementMethod());
                }
                v.setText(arr.getString(3));
            }
            return;
        }

        if (type.equals("edit-text")) {
            EditText v = (EditText) vv;
            if (token.equals("text")) {
                v.setText(arr.getString(3));
            }
            if (token.equals("request-focus")) {
                v.requestFocus();
                InputMethodManager imm = (InputMethodManager) ctx
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT);
            }
            return;
        }

        if (type.equals("button")) {
            Button v = (Button) vv;
            if (token.equals("text")) {
                v.setText(arr.getString(3));
            }

            if (token.equals("listener")) {
                final String fn = arr.getString(3);
                v.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        m_Scheme.eval("(" + fn + ")");
                    }
                });
            }
            return;
        }

        if (type.equals("toggle-button")) {
            ToggleButton v = (ToggleButton) vv;
            if (token.equals("text")) {
                v.setText(arr.getString(3));
                return;
            }

            if (token.equals("checked")) {
                if (arr.getInt(3) == 0)
                    v.setChecked(false);
                else
                    v.setChecked(true);
                return;
            }

            if (token.equals("listener")) {
                final String fn = arr.getString(3);
                v.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        m_Scheme.eval("(" + fn + ")");
                    }
                });
            }
            return;
        }

        if (type.equals("canvas")) {
            StarwispCanvas v = (StarwispCanvas) vv;
            if (token.equals("drawlist")) {
                v.SetDrawList(arr.getJSONArray(3));
            }
            return;
        }

        if (type.equals("camera-preview")) {
            final CameraPreview v = (CameraPreview) vv;

            if (token.equals("take-picture")) {
                final String path = ((StarwispActivity) ctx).m_AppDir + arr.getString(3);

                v.TakePicture(new PictureCallback() {
                    public void onPictureTaken(byte[] data, Camera camera) {
                        String datetime = getDateTime();
                        String filename = path + datetime + ".jpg";
                        SaveData(filename, data);
                        v.Shutdown();
                        ctx.finish();
                    }
                });
            }

            if (token.equals("shutdown")) {
                v.Shutdown();
            }

            return;
        }

        if (type.equals("seek-bar")) {
            SeekBar v = new SeekBar(ctx);
            if (token.equals("max")) {
                // android seekbar bug workaround
                int p = v.getProgress();
                v.setMax(0);
                v.setProgress(0);
                v.setMax(arr.getInt(3));
                v.setProgress(1000);

                // not working.... :(
            }
        }

        if (type.equals("spinner")) {
            Spinner v = (Spinner) vv;

            if (token.equals("selection")) {
                v.setSelection(arr.getInt(3));
            }

            if (token.equals("array")) {
                final JSONArray items = arr.getJSONArray(3);
                ArrayList<String> spinnerArray = new ArrayList<String>();

                for (int i = 0; i < items.length(); i++) {
                    spinnerArray.add(items.getString(i));
                }

                ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<String>(ctx,
                        android.R.layout.simple_spinner_item, spinnerArray) {
                    public View getView(int position, View convertView, ViewGroup parent) {
                        View v = super.getView(position, convertView, parent);
                        ((TextView) v).setTypeface(((StarwispActivity) ctx).m_Typeface);
                        return v;
                    }
                };

                v.setAdapter(spinnerArrayAdapter);

                final int wid = id;
                // need to update for new values
                v.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                    public void onItemSelected(AdapterView<?> a, View v, int pos, long id) {
                        try {
                            CallbackArgs(ctx, ctxname, wid, "\"" + items.getString(pos) + "\"");
                        } catch (JSONException e) {
                            Log.e("starwisp", "Error parsing data " + e.toString());
                        }
                    }

                    public void onNothingSelected(AdapterView<?> v) {
                    }
                });

            }
            return;
        }

    } catch (JSONException e) {
        Log.e("starwisp", "Error parsing data " + e.toString());
    }
}

From source file:im.vector.activity.CallViewActivity.java

/**
 * Start the ringing sound//ww w .  ja va  2  s.  co m
 */
public static void startRinging(Context context) {
    Log.d(LOG_TAG, "startRinging");

    if (null != mRingTone) {
        Log.d(LOG_TAG, "already ringing");
        return;
    }

    // use the ringTone to manage sound volume properly
    // else the ringing volume is linked to the media volume.
    mRingTone = getRingTone(context, R.raw.ring, "ring.ogg");
    if (null != mRingTone) {

        if (null != mRingbackTone) {
            mRingbackTone.stop();
            mRingbackTone = null;
        }

        if (null != mCallEndTone) {
            mCallEndTone.stop();
            mCallEndTone = null;
        }

        MXCallsManager.setSpeakerphoneOn(context, true);
        mRingTone.play();
        return;
    }

    if (null == mRingingPlayer) {
        mRingingPlayer = MediaPlayer.create(context.getApplicationContext(), R.raw.ring);

        if (null != mRingingPlayer) {
            mRingingPlayer.setLooping(true);
            mRingingPlayer.setVolume(1.0f, 1.0f);
        }
    }

    if (null != mRingingPlayer) {
        // check if it is not yet playing
        if (!mRingingPlayer.isPlaying()) {
            // stop pending
            if ((null != mCallEndPlayer) && mCallEndPlayer.isPlaying()) {
                mCallEndPlayer.stop();
            }

            if ((null != mRingbackPlayer) && mRingbackPlayer.isPlaying()) {
                mRingbackPlayer.stop();
            }

            MXCallsManager.setSpeakerphoneOn(context, true);
            mRingingPlayer.start();
        }
    }
}

From source file:fiskinfoo.no.sintef.fiskinfoo.MapFragment.java

private void notifyUserOfProximityAlert() {
    Handler mainHandler = new Handler(getActivity().getMainLooper());

    Runnable myRunnable = new Runnable() {
        @Override//from   w w  w .j a  va  2  s . co  m
        public void run() {
            final Dialog dialog = dialogInterface.getDialog(getActivity(),
                    R.layout.dialog_proximity_alert_warning, R.string.proximity_alert_warning);

            Button okButton = (Button) dialog.findViewById(R.id.proximity_alert_warning_ok_button);
            Button showOnMapButton = (Button) dialog
                    .findViewById(R.id.proximity_alert_warning_show_on_map_button);
            Button dismissAlertButton = (Button) dialog
                    .findViewById(R.id.proximity_alert_warning_dismiss_button);

            long[] pattern = { 0, 500, 200, 200, 300, 200, 200 };

            vibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
            vibrator.vibrate(pattern, 0);

            mediaPlayer = MediaPlayer.create(getActivity(), R.raw.proximity_warning_sound);

            if (mediaPlayer == null) {
                return;
            }

            mediaPlayer.setLooping(true);
            mediaPlayer.start();

            okButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    alarmFiring = false;
                    vibrator.cancel();
                    vibrator = null;
                    proximityAlertWatcher.cancel(true);
                    proximityAlertWatcher = null;
                    mediaPlayer.stop();
                    mediaPlayer.release();

                    dialog.dismiss();
                    runScheduledAlarm(getResources().getInteger(R.integer.sixty),
                            getResources().getInteger(R.integer.proximity_alert_interval_time_seconds));
                }
            });

            showOnMapButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    alarmFiring = false;
                    vibrator.cancel();
                    vibrator = null;
                    proximityAlertWatcher.cancel(true);
                    proximityAlertWatcher = null;
                    mediaPlayer.stop();
                    mediaPlayer.release();

                    browser.loadUrl("javascript:zoomToUserPosition()");

                    dialog.dismiss();
                    runScheduledAlarm(getResources().getInteger(R.integer.sixty),
                            getResources().getInteger(R.integer.proximity_alert_interval_time_seconds));

                }
            });

            dismissAlertButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    alarmFiring = false;
                    vibrator.cancel();
                    vibrator = null;
                    proximityAlertWatcher.cancel(true);
                    proximityAlertWatcher = null;
                    mediaPlayer.stop();
                    mediaPlayer.release();

                    dialog.dismiss();
                }
            });

            dialog.show();
        } // This is your code
    };
    mainHandler.post(myRunnable);
}

From source file:im.vector.activity.CallViewActivity.java

/**
 * Start the ringback sound//from w w  w  .  j  av a2  s.co m
 */
public static void startRingbackSound(Context context) {
    Log.d(LOG_TAG, "startRingbackSound");

    if (null != mRingTone) {
        Log.d(LOG_TAG, "already ringing");
        return;
    }

    // use the ringTone to manage sound volume properly
    // else the ringing volume is linked to the media volume.
    mRingbackTone = getRingTone(context, R.raw.ringback, "ringback.ogg");

    if (null != mRingbackTone) {
        if (null != mRingTone) {
            mRingTone.stop();
            mRingTone = null;
        }

        if (null != mCallEndTone) {
            mCallEndTone.stop();
            mCallEndTone = null;
        }

        MXCallsManager.setSpeakerphoneOn(context, true);
        mRingbackTone.play();
        return;
    }

    if (null == mRingbackPlayer) {
        mRingbackPlayer = MediaPlayer.create(context.getApplicationContext(), R.raw.ringback);

        if (null != mRingbackPlayer) {
            mRingbackPlayer.setLooping(true);
            mRingbackPlayer.setVolume(1.0f, 1.0f);
        }
    }

    if (null != mRingbackPlayer) {
        // check if it is not yet playing
        if (!mRingbackPlayer.isPlaying()) {
            // stop pending
            if ((null != mCallEndPlayer) && mCallEndPlayer.isPlaying()) {
                mCallEndPlayer.stop();
            }

            if ((null != mRingingPlayer) && mRingingPlayer.isPlaying()) {
                mRingingPlayer.stop();
            }

            MXCallsManager.setSpeakerphoneOn(context, true);
            mRingbackPlayer.start();
        }
    }
}

From source file:com.insthub.O2OMobile.Activity.C1_PublishOrderActivity.java

/**
 * ?//from  w  w w. j  a v  a 2 s.c  o  m
 */
private void stopRecording() {
    if (mTimer != null) {
        mTimer.cancel(); //??
    }
    mTimer = null;
    if (mRecorder != null) {
        try {
            mRecorder.stop();
            mRecorder.reset();
            mRecorder.release();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        }
    }
    mRecorder = null;

    MediaPlayer mp = MediaPlayer.create(this, Uri.parse(mFileName));
    if (null != mp) {
        int duration = mp.getDuration();//? ms
        if (duration > 3000) {
            mVoice.setVisibility(View.GONE);
            mVoicePlay.setVisibility(View.VISIBLE);
            mVoiceReset.setVisibility(View.VISIBLE);
        } else {
            ToastView toast = new ToastView(C1_PublishOrderActivity.this,
                    getString(R.string.record_time_too_short));
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            File file = new File(newFileName());
            if (file.exists()) {
                file.delete();
            }
        }
        mp.release();
    }
    mVoice.setKeepScreenOn(false);
}

From source file:com.aimfire.demo.CamcorderActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (BuildConfig.DEBUG)
        Log.d(TAG, "create CamcorderActivity");

    loadPrefs();/* w w w .j a va 2s  .c o  m*/

    /*
     *  keep the screen on until we turn off the flag 
     */
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_camcorder);

    /*
     * Obtain the FirebaseAnalytics instance.
     */
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);

    /*
     * disable nfc push
     */
    NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (nfcAdapter != null)
        nfcAdapter.setNdefPushMessage(null, this);

    /*
     * get the natural orientation of this device. need to be called before
     * we fix the display orientation
     */
    mNaturalOrientation = getDeviceDefaultOrientation();

    /*
     * force CamcorderActivity in landscape because it is the natural 
     * orientation of the camera sensor
     */
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    /*
     * get the orientation for SCREEN_ORIENTATION_LANDSCAPE mode. this is the 
     * clockwise rotation of landscape mode from device natural orientation.
     * reverse landscape is 180 degrees different. call this *after* the
     * display orientation is fixed, because only then getDefaultDisplay().
     * getRotation() will consistently return the value we require.
     */
    mLandscapeOrientation = getDeviceLandscapeOrientation();

    /*
     * apply the adapter to the spinner - for filter selection.
     */
    /*
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
    R.array.cameraFilterNames, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(this);
    */

    mParentView = getActivity().getWindow().getDecorView();

    mCaptureButton = (ImageButton) findViewById(R.id.toggle_recording_button);
    mView3DButton = (ImageButton) findViewById(R.id.view3D_button);
    mExitButton = (ImageButton) findViewById(R.id.exit_button);
    mPvButton = (ImageButton) findViewById(R.id.switch_photo_video_button);
    mFbButton = (ImageButton) findViewById(R.id.switch_front_back_button);
    mLevelButton = (Button) findViewById(R.id.level_button);
    mTimeCounter = (LinearLayout) findViewById(R.id.time_counter);
    mScanModeButton = (ImageButton) findViewById(R.id.mode_button);

    mCaptureButton.setOnClickListener(oclToggle);
    mView3DButton.setOnClickListener(oclView3D);
    mExitButton.setOnClickListener(oclExit);
    mPvButton.setOnClickListener(oclPV);
    mFbButton.setOnClickListener(oclFB);
    mScanModeButton.setOnClickListener(oclSwitchMode);

    mShutterLayout = (FrameLayout) findViewById(R.id.shutter_layout);
    mProgView = (ImageView) findViewById(R.id.circular_progress_view);

    mProgDrawable = new com.aimfire.utilities.CircularProgressDrawable.Builder().setRingWidth(10)
            .setRingColor(getResources().getColor(R.color.orange)).create();

    mProgView.setImageDrawable(mProgDrawable);

    mScanProgView = (ImageView) findViewById(R.id.scan_circular_progress_view);
    mScanProgView.setOnClickListener(oclScan);

    int[] centerGradient = new int[] { getResources().getColor(R.color.start_button_start_color_pressed),
            getResources().getColor(R.color.start_button_end_color_pressed) };

    mScanProgDrawable = new com.aimfire.utilities.CircularProgressDrawable.Builder().setRingWidth(10)
            .setInnerCircleScale(1.0f).setOutlineColor(getResources().getColor(R.color.dark_grey))
            .setRingColor(getResources().getColor(R.color.white))
            .setArcColor(getResources().getColor(android.R.color.holo_blue_dark))
            .setCenterGradient(centerGradient).setWifiBarColor(getResources().getColor(R.color.blue))
            .setMessageSize((int) (10/*sp*/ * getResources().getDisplayMetrics().density))
            .setMessageColor(getResources().getColor(R.color.white)).create();

    mScanProgView.setImageDrawable(mScanProgDrawable);

    /*
     * showing animation for searching remote device
     */
    startScanAnim();

    String startSound = null;
    String stopSound = null;
    for (String s : CAMERA_RECORDING_START_SOUND) {
        if ((new File(s)).exists()) {
            startSound = s;
            break;
        }
    }

    if (startSound != null) {
        mCamStartSoundPlayer = MediaPlayer.create(this, Uri.fromFile(new File(startSound)));
    }

    for (String s : CAMERA_RECORDING_STOP_SOUND) {
        if ((new File(s)).exists()) {
            stopSound = s;
            break;
        }
    }

    if (stopSound != null) {
        mCamStopSoundPlayer = MediaPlayer.create(this, Uri.fromFile(new File(stopSound)));
    }

    /*
     * file name prefix for solo mode. rest of the file name (date and time stamp) are
     * added when recording starts.
     */
    mMpegPrefixSolo = MainConsts.MEDIA_3D_SAVE_PATH + "MPG_solo_";

    /*
     * place UI controls at their initial, default orientation
     */
    adjustUIControls(0);

    /*
     * load the thumbnail of the newest movie to the view3D button
     */
    loadCurrThumbnail();

    /*
     * attempt to open camera with desired dimension. the dimension may be
     * changed if camera doesn't support it, in which case the "preferred" 
     * (by the camera) dimension will be used
     */
    boolean success = openCamera(Camera.CameraInfo.CAMERA_FACING_BACK, mQualityPref);

    if (!success) {
        Toast.makeText(this, R.string.error_opening_camera, Toast.LENGTH_LONG).show();

        finish();
        return;
    }

    /*
     * define a handler that receives camera-control messages from other threads.  
     * all calls to Camera must be made on the same thread.  note we create this 
     * before the renderer thread, so we know the fully-constructed object will 
     * be visible.
     */
    mCameraHandler = new CameraHandler(this);

    /*
     * configure the GLSurfaceView.  this will start the Renderer thread, with an
     * appropriate EGL context.
     */
    mGLView = (GLSurfaceView) findViewById(R.id.cameraPreview_surfaceView);
    mGLView.setEGLContextClientVersion(2); // select GLES 2.0
    mRenderer = new CameraSurfaceRenderer(mCameraHandler, mMovieEncoder);
    mGLView.setRenderer(mRenderer);
    mGLView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
    mGLView.setOnTouchListener(otl);

    /*
     * bind to Aimfire service
     */
    mAimfireServiceConn = new AimfireServiceConn(this);

    /*
     * binding doesn't happen until later. wait for it to happen in another 
     * thread and connect to p2p peer if necessary
     */
    (new Thread(mAimfireServiceInitTask)).start();

    /*
     * register for AimfireService message broadcast
     */
    LocalBroadcastManager.getInstance(this).registerReceiver(mAimfireServiceMsgReceiver,
            new IntentFilter(MainConsts.AIMFIRE_SERVICE_MESSAGE));

    /*
     * register for intents sent by the media processor service
     */
    LocalBroadcastManager.getInstance(this).registerReceiver(mMovieProcessorMsgReceiver,
            new IntentFilter(MainConsts.MOVIE_PROCESSOR_MESSAGE));

    /*
     * register for intents sent by the media processor service
     */
    LocalBroadcastManager.getInstance(this).registerReceiver(mMovieEncoderMsgReceiver,
            new IntentFilter(MainConsts.MOVIE_ENCODER_MESSAGE));
}