package com.allengarvey.annuncified;

import android.app.Activity;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;

/**
 * Created by Allen X on 5/15/15.
 */
public class ChangeNotificationsActivity extends ActionBarActivity{
    //Declare UI elements
    private Button defaultNotificationbutton;

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.change_notifications_layout);
        //Inflate UI
        defaultNotificationbutton = (Button) findViewById(R.id.defaultNotificationbutton);

        setDefaultDisplayButtonText(NotifyUtil.getDefaultNotificationSound(this));
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu){
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item){
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();


        return super.onOptionsItemSelected(item);
    }


    public void setNotificationSound(View v){
        Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Default Tone");
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, NotifyUtil.getDefaultNotificationSound(this));
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
        this.startActivityForResult(intent, 5);

    }

    @Override
    protected void onActivityResult(final int requestCode, final int resultCode, final Intent intent)
    {
        if (resultCode == Activity.RESULT_OK && requestCode == 5)
        {
            Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);

            if (uri != null){
                setDefaultDisplayButtonText(uri);
                NotifyUtil.getSharedPreferences(this).edit()
                        .putString(getString(R.string.default_notification_sound_uri_shared_preferences_key), uri.toString())
                        .apply();

            }

        }
    }

    public void contactNotificationSoundsActivityLaunch(View v){
        startActivity(new Intent(ChangeNotificationsActivity.this, ContactNotificationSoundsActivity.class));

    }

    private void setDefaultDisplayButtonText(Uri ringtoneUri){
        setDefaultDisplayButtonText(NotifyUtil.ringtoneNameFromUri(this, ringtoneUri));
    }

    private void setDefaultDisplayButtonText(String ringtoneUriName){
        defaultNotificationbutton.setText(ringtoneUriName);
    }


}
@@ -52,32 +52,65 @@
 d.app.Activity;%0A
+import android.app.ListActivity;%0A
 import android.c
@@ -216,57 +216,8 @@
 le;%0A
-import android.support.v7.app.ActionBarActivity;%0A
 impo
@@ -320,58 +320,54 @@
 get.
-Button;%0A%0A/**%0A * Created by Allen X on 5/15/15.%0A */
+ArrayAdapter;%0Aimport android.widget.ListView;%0A
 %0Apub
@@ -416,17 +416,12 @@
 nds 
-ActionBar
+List
 Acti
@@ -464,22 +464,90 @@
 private 
-Button
+String%5B%5D menuList;%0A    private ArrayAdapter%3CString%3EmenuAdapter;%0A    String
  default
@@ -558,22 +558,20 @@
 fication
-button
+Text
 ;%0A%0A    @
@@ -691,153 +691,311 @@
     
-setContentView(R.layout.change_notifications_layout);%0A        //Inflate UI%0A        defaultNotificationbutton = (Button) findViewById(R.id
+menuList = new String%5B%5D%7B%22%22, getResources().getString(R.string.custom_notification_text)%7D;%0A        menuAdapter = new ArrayAdapter%3C%3E(this, R.layout.wide_list_layout, R.id.list_item, menuList);%0A        setListAdapter(menuAdapter);%0A        defaultNotificationText = getResources().getString(R.string
 .default
 Noti
@@ -986,33 +986,34 @@
 ring.default
-N
+_n
 otificat
 ionbutton);%0A
@@ -1004,21 +1004,18 @@
 icat
-i
 on
-button
+_text
 );%0A
-%0A
     
@@ -1024,35 +1024,34 @@
   setDefault
-DisplayButt
+Notificati
 onText(Notif
@@ -1613,44 +1613,8 @@
 ml.%0A
-        int id = item.getItemId();%0A%0A
 %0A   
@@ -1705,22 +1705,16 @@
 onSound(
-View v
 )%7B%0A     
@@ -2558,35 +2558,34 @@
   setDefault
-DisplayButt
+Notificati
 onText(uri);
@@ -2806,17 +2806,16 @@
 pply();%0A
-%0A
         
@@ -2816,25 +2816,24 @@
           %7D%0A
-%0A
         %7D%0A  
@@ -2841,73 +2841,238 @@
  %7D%0A%0A
-    public void contactNotificationSoundsActivityLaunch(View v)%7B%0A
+%0A    @Override%0A    protected void onListItemClick(ListView l, View v, int postion, long id)%7B%0A        switch(postion)%7B%0A            case 0:%0A                setNotificationSound();%0A                break;%0A            default:%0A        
     
@@ -3177,24 +3177,56 @@
 lass));%0A
+                break;%0A        %7D
 %0A    %7D%0A%0A
     priv
@@ -3209,32 +3209,34 @@
        %7D%0A    %7D%0A%0A
+%0A%0A
     private void
@@ -3242,35 +3242,34 @@
 d setDefault
-DisplayButt
+Notificati
 onText(Uri r
@@ -3295,35 +3295,34 @@
   setDefault
-DisplayButt
+Notificati
 onText(Notif
@@ -3406,19 +3406,18 @@
 ault
-DisplayButt
+Notificati
 onTe
@@ -3443,32 +3443,46 @@
 riName)%7B%0A       
+ menuList%5B0%5D =
  defaultNotifica
@@ -3489,38 +3489,80 @@
 tion
-button.setText(ringtoneUriName
+Text + %22%5Cn%22 + ringtoneUriName;%0A        menuAdapter.notifyDataSetChanged(
 );%0A 

modify changenotificationsactivity to listactivity instead of using custom layout