Android Open Source - RadioRake Confirm Details Activity






From Project

Back to project page RadioRake.

License

The source code is released under:

GNU General Public License

If you think the Android project RadioRake listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.asp.radiorake;
/*  ww w. ja va 2s.  co m*/
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.asp.radiorake.utils.StringUtils;
import com.aspillai.R;

import java.io.IOException;


public class ConfirmDetailsActivity extends Activity implements View.OnClickListener {

    private static final String TAG = "com.asp.radiorake.ConfirmDetailsActivity";
    private int MODE;
    private long radioDetailsId;

    private final int ADD_NEW_MODE = 0;
    private final int EDIT_MODE = 1;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.edit_fav_pop_up);

        Bundle bundle = this.getIntent().getExtras();

        RadioDetails radioDetails = null;

        if (bundle.getLong(getString(R.string.edit_favourite_id)) > 0) {
            // Edit mode
            MODE = EDIT_MODE;
            DatabaseHelper dbHelper = new DatabaseHelper(this);

            try {
                dbHelper.openDataBase();
                radioDetails = dbHelper.getFavourite(bundle.getLong(getString(R.string.edit_favourite_id)));
                radioDetailsId = bundle.getLong(getString(R.string.edit_favourite_id));
            } catch (IOException e) {
                Log.e(TAG, "IOException thrown when trying to access DB", e);
            } finally {
                dbHelper.close();
            }
        } else {
            // New mode
            MODE = ADD_NEW_MODE;
            radioDetails = bundle.getParcelable(getString(R.string.radio_details_key));
        }

        EditText txtName = (EditText) findViewById(R.id.edit_fav_pop_up_txt_name);
        EditText txtUrl = (EditText) findViewById(R.id.edit_fav_pop_up_txt_url);

        if (radioDetails != null) {
            txtName.setText(radioDetails.getStationName());
            if (StringUtils.IsNullOrEmpty(radioDetails.getPlaylistUrl())) {
                txtUrl.setText(radioDetails.getStreamUrl());
            } else {
                txtUrl.setText(radioDetails.getPlaylistUrl());
            }
            radioDetails.setStationName(txtName.getText().toString());
            radioDetails.setStreamUrl(txtUrl.getText().toString());
        }


        Button cancelButton = (Button) findViewById(R.id.edit_fav_pop_up_btn_cancel);
        Button saveButton = (Button) findViewById(R.id.edit_fav_pop_up_btn_save);

        cancelButton.setOnClickListener(this);
        saveButton.setOnClickListener(this);
    }

    public void onClick(View view) {

        Intent intent = new Intent(ConfirmDetailsActivity.this, RadioActivity.class);

        String txtName = ((EditText) findViewById(R.id.edit_fav_pop_up_txt_name)).getText().toString();
        String txtUrl = ((EditText) findViewById(R.id.edit_fav_pop_up_txt_url)).getText().toString();

        RadioDetails radioDetails = new RadioDetails(radioDetailsId, txtName, null, null);

        if (txtUrl.endsWith(".pls") || txtUrl.endsWith(".m3u")) {
            radioDetails.setPlaylistUrl(txtUrl);
        } else {
            radioDetails.setStreamUrl(txtUrl);
        }

        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

        switch (view.getId()) {

            case R.id.edit_fav_pop_up_btn_save:

                if (txtName.equals("")) {
                    Toast.makeText(this, "Please enter a name before saving", Toast.LENGTH_SHORT).show();
                    return;
                }

                if (txtUrl.equals("")) {
                    Toast.makeText(this, "Please enter a URL before saving", Toast.LENGTH_SHORT).show();
                    return;
                }

                DatabaseHelper dbHelper = new DatabaseHelper(this);

                try {
                    dbHelper.openDataBase();
                    switch (MODE) {
                        case EDIT_MODE:
                            dbHelper.updateFavourite(radioDetails);
                            break;
                        case ADD_NEW_MODE:
                            dbHelper.addFavourite(radioDetails);
                            break;
                    }
                } catch (IOException e) {
                    Log.e(TAG, "IOException thrown when trying to access DB", e);
                } finally {
                    dbHelper.close();
                }

                imm.hideSoftInputFromWindow(findViewById(R.id.edit_fav_pop_up_txt_name).getWindowToken(), 0);

                finish();
                break;

            case R.id.edit_fav_pop_up_btn_cancel:
                onBackPressed();
                imm.hideSoftInputFromWindow(findViewById(R.id.edit_fav_pop_up_txt_name).getWindowToken(), 0);
                break;
        }


    }

    @Override
    public void onBackPressed() {
        Intent RadioActivityIntent = new Intent(ConfirmDetailsActivity.this, RadioActivity.class);
        startActivity(RadioActivityIntent);
        finish();
    }
}




Java Source Code List

com.asp.radiorake.AddNewScheduledRecordingActivity.java
com.asp.radiorake.AlarmHelper.java
com.asp.radiorake.CallReceiver.java
com.asp.radiorake.ConfirmDetailsActivity.java
com.asp.radiorake.DatabaseHelper.java
com.asp.radiorake.DatePickerFragment.java
com.asp.radiorake.LastPlayedFile.java
com.asp.radiorake.ListScheduledRecordingsActivity.java
com.asp.radiorake.NotificationHelper.java
com.asp.radiorake.PlayerService.java
com.asp.radiorake.PlayingFile.java
com.asp.radiorake.RadioActivity.java
com.asp.radiorake.RadioApplication.java
com.asp.radiorake.RadioDetails.java
com.asp.radiorake.RebootBroadcastReceiver.java
com.asp.radiorake.RecordingsActivity.java
com.asp.radiorake.RecordioBaseActivity.java
com.asp.radiorake.RemoteControlReceiver.java
com.asp.radiorake.ScheduledRecordingsCursorAdaptor.java
com.asp.radiorake.TimePickerFragment.java
com.asp.radiorake.filehandling.FileHandler.java
com.asp.radiorake.filehandling.M3uHandler.java
com.asp.radiorake.filehandling.PlsHandler.java
com.asp.radiorake.recording.RecorderService.java
com.asp.radiorake.recording.RecordingBroadcastReceiver.java
com.asp.radiorake.utils.DateUtils.java
com.asp.radiorake.utils.StringUtils.java