Example usage for android.media RingtoneManager EXTRA_RINGTONE_TYPE

List of usage examples for android.media RingtoneManager EXTRA_RINGTONE_TYPE

Introduction

In this page you can find the example usage for android.media RingtoneManager EXTRA_RINGTONE_TYPE.

Prototype

String EXTRA_RINGTONE_TYPE

To view the source code for android.media RingtoneManager EXTRA_RINGTONE_TYPE.

Click Source Link

Document

Given to the ringtone picker as an int.

Usage

From source file:com.mattprecious.notisync.profile.SecondaryCustomProfileActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.profile_custom_secondary);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    dbAdapter = new DbAdapter(this);

    if (getIntent().hasExtra("profile")) {
        profile = getIntent().getParcelableExtra("profile");
    } else {/* w  w  w  .j  a  v  a2 s .c  o  m*/
        profile = new SecondaryProfile();
        profile.setEnabled(true);
        profile.setVibrate(true);
        profile.setLed(true);
    }

    nameField = (EditText) findViewById(R.id.nameField);
    nameField.setText(profile.getName());
    nameField.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                validateName();

                if (tagField.getText().length() == 0) {
                    tagField.setText(nameField.getText().toString().toLowerCase(Locale.getDefault())
                            .replaceAll("\\s", ""));
                    validateTag();
                }
            }
        }

    });

    tagField = (EditText) findViewById(R.id.tagField);
    tagField.setText(profile.getTag());
    tagField.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                validateTag();
            }

        }

    });

    tagRequestButton = (ImageButton) findViewById(R.id.tagRequestButton);
    tagRequestButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            SherlockDialogFragment newFragment = new RequestTagsDialogFragment();
            newFragment.show(getSupportFragmentManager(), null);
        }

    });

    unconnectedOnlyCheckBox = (CheckBox) findViewById(R.id.unconnectedOnlyCheckBox);
    unconnectedOnlyCheckBox.setChecked(profile.isUnconnectedOnly());

    ringtoneSelector = (Button) findViewById(R.id.ringtoneSelector);
    ringtoneSelector.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI,
                    RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, getRingtoneUri(profile.getRingtone()));

            startActivityForResult(intent, REQUEST_CODE_RINGTONE_PICKER);

        }
    });

    vibrateCheckBox = (CheckBox) findViewById(R.id.vibrateCheckBox);
    vibrateCheckBox.setChecked(profile.isVibrate());

    checkForVibrator();

    lightsCheckBox = (CheckBox) findViewById(R.id.lightsCheckBox);
    lightsCheckBox.setChecked(profile.isLed());

    updateRingtoneSelector();
}

From source file:rikka.materialpreference.RingtonePreference.java

/**
 * Prepares the intent to launch the ringtone picker. This can be modified
 * to adjust the parameters of the ringtone picker.
 *
 * @param ringtonePickerIntent The ringtone picker intent that can be
 *            modified by putting extras.
 *//*  www . ja  va 2 s. co  m*/
protected void onPrepareRingtonePickerIntent(Intent ringtonePickerIntent) {

    ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, onRestoreRingtone());

    ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, mShowDefault);
    if (mShowDefault) {
        ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI,
                RingtoneManager.getDefaultUri(getRingtoneType()));
    }

    ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, mShowSilent);
    ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, mRingtoneType);
    ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, getTitle());
}

From source file:org.schabi.terminightor.AlarmItemDetailFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    lastSavedInstaneState = savedInstanceState;
    Activity a = getActivity();/*from w w w.  j  ava2  s. com*/
    setAlarmTimeView = (TextView) a.findViewById(R.id.setAlarmTimeView);
    setAlarmAMPMView = (TextView) a.findViewById(R.id.setAlarmAmPmSuffix);
    repeatCheckBox = (CheckBox) a.findViewById(R.id.setRepeatCheckBox);
    chooseDateView = (ChooseDaysView) a.findViewById(R.id.chooseDateView);
    alarmLabelBox = (EditText) a.findViewById(R.id.setAlarmLabelBox);
    setAlarmToneButton = (Button) a.findViewById(R.id.setAlarmToneButton);
    vibrateCheckBox = (CheckBox) a.findViewById(R.id.vibrateCheckBox);
    nfcTagLabelView = (ImageView) a.findViewById(R.id.nfcTagLabelView);
    nfcTagIdView = (TextView) a.findViewById(R.id.nfcTagIdView);
    addNfcTabButton = (FloatingActionButton) a.findViewById(R.id.addNfcTagButton);

    repeatCheckBox.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (repeatCheckBox.isChecked()) {
                chooseDateView.setVisibility(View.VISIBLE);
            } else {
                chooseDateView.setVisibility(View.GONE);
            }
            chooseDateView.setRepeatEnabled(repeatCheckBox.isChecked());
        }
    });

    setAlarmTimeView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            timePickerDialog.show();
        }
    });

    setAlarmToneButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE,
                    getResources().getString(R.string.selectAlarmToneTitle));
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_ALARM);
            if (!alarm.getAlarmTone().isEmpty()) {
                intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(alarm.getAlarmTone()));
            }
            startActivityForResult(intent, SET_ALARM_TONE);
        }
    });

    addNfcTabButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), SetTagActivity.class);
            startActivityForResult(intent, READ_NFC_ID);
        }
    });
}

From source file:com.example.mydemos.view.RingtonePickerActivity.java

/** Called when the activity is first created. */
@Override/*www.j  ava2 s.c  o  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.ringtone_picker);
    CharSequence sysTitle = (CharSequence) getResources().getText(R.string.sys_tone);
    CharSequence MusicTitle = (CharSequence) getResources().getText(R.string.sd_music);
    CharSequence RecordTitle = (CharSequence) getResources().getText(R.string.record_tone);
    Intent intent = getIntent();
    toneType = intent.getIntExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, -1);

    Log.e("duwenhua", "ringPick get toneType:" + toneType);

    //! by duwenhua
    //if(toneType == RingtoneManager.TYPE_RINGTONE_SECOND)
    //    toneType = RINGTONE_TYPE;

    //! by duwenhua
    mHasDefaultItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
    mUriForDefaultItem = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI);
    //Log.i("lys", "mUriForDefaultItem == " + mUriForDefaultItem);
    if (savedInstanceState != null) {
        mSelectedId = savedInstanceState.getLong(SAVE_CLICKED_POS, -1);
    }
    //Log.i("lys", "mUriForDefaultItem 1== " + mUriForDefaultItem+", mSelectedId =="+mSelectedId);      
    mHasSilentItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
    mExistingUri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI);
    //if(mUriForDefaultItem != null)
    //{
    //    mSelectedId = ContentUris.parseId(mUriForDefaultItem);
    //}

    //Log.i("lys", "RingtonePickerActivity.java onCreate mExistingUri == " + mExistingUri);   
    //String action = getIntent().getAction();
    //Log.i("lys", "PT Intent action == " + action);

    if (toneType == NOTIFICATION_TYPE) {
        mUriForDefaultItem = Settings.System.DEFAULT_NOTIFICATION_URI;
    } else if (toneType == RINGTONE_TYPE) {
        mUriForDefaultItem = Settings.System.DEFAULT_RINGTONE_URI;
    } else if (toneType == ALARM_TYPE) {
        mUriForDefaultItem = Settings.System.DEFAULT_ALARM_ALERT_URI;
    }

    if (isAvailableToCheckRingtone() == true) {
        Ringtone ringtone_DefaultItem = checkRingtone_reflect(this, mUriForDefaultItem, toneType);
        if (ringtone_DefaultItem != null && ringtone_DefaultItem.getUri() != null) {
            mUriForDefaultItem = ringtone_DefaultItem.getUri();
            Log.i("lys", "RingtoneManager.getRingtone  mUriForDefaultItem== " + mUriForDefaultItem);
        } else {
            //mUriForDefaultItem = 'content/medial/';
            /*ZTE_AUDIO_LIYANG 2014/06/30 fix bug for ringtone when remove sdcard start */
            String originalRingtone = Settings.System.getString(getApplicationContext().getContentResolver(),
                    "ringtone_original");
            if (originalRingtone != null && !TextUtils.isEmpty(originalRingtone)) {
                mUriForDefaultItem = Uri.parse(originalRingtone);
                Log.e("liyang", "select riongtone error  ,change to originalRingtone == " + mExistingUri);
            }
            /*ZTE_AUDIO_LIYANG 2014/06/30 fix bug for ringtone when remove sdcard end */
            Log.i("lys", "mUriForDefaultItem set as default mUriForDefaultItem== 222");
        }

        if (mExistingUri != null) {
            Ringtone ringtone = checkRingtone_reflect(this, mExistingUri, toneType);
            if (ringtone != null && ringtone.getUri() != null) {
                //mUriForDefaultItem = ringtone.getUri(); 
                mExistingUri = ringtone.getUri();
                Log.i("lys", "RingtoneManager.getRingtone  mExistingUri== " + mExistingUri);
            } else {
                mExistingUri = mUriForDefaultItem;
                Log.i("lys", "mExistingUri set as default mExistingUri== " + mExistingUri);
            }
        }
    }

    boolean includeDrm = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_INCLUDE_DRM, false);
    Log.e("lys", "includeDrm ==" + includeDrm);
    mRingtoneManager = new RingtoneManager(this);
    mRingtoneManager.setIncludeDrm(includeDrm);
    if (toneType != -1) {
        mRingtoneManager.setType(toneType);
    }

    setVolumeControlStream(mRingtoneManager.inferStreamType());
    //   toneActivityType = mRingtoneManager.getActivityType();
    if (toneType == ALARM_TYPE) {
        sysTitle = (CharSequence) getResources().getText(R.string.alarm_tone);
    } else if (toneType == NOTIFICATION_TYPE) {
        sysTitle = (CharSequence) getResources().getText(R.string.notification_tone);
    }

    listView = new ListView(this);
    listView.setOnItemClickListener(this);
    //listView.setBackgroundColor(#ff5a5a5a);
    listView.setFastScrollEnabled(true);
    //listView.setFastScrollAlwaysVisible(true);
    listView.setEmptyView(findViewById(android.R.id.empty));
    //mHasSilentItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);

    //mHasDefaultItem = true; //temp
    if (mHasDefaultItem) {
        //chengcheng
        addDefaultStaticItem(listView, com.android.internal.R.string.ringtone_default);

    }

    setDefaultRingtone();

    if (mHasSilentItem) {
        // chengcheng
        addSilendStaticItem(listView, com.android.internal.R.string.ringtone_silent);
    }
    audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mAudioFocusListener = new OnAudioFocusChangeListener() {
        public void onAudioFocusChange(int focusChange) {

        }
    };

    okBtn = (Button) findViewById(R.id.ok);
    okBtn.setOnClickListener(this);
    cancelBtn = (Button) findViewById(R.id.cancel);
    cancelBtn.setOnClickListener(this);

    TabHost mTabHost = (TabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup();
    mTabHost.addTab(mTabHost.newTabSpec("tab_system").setIndicator(sysTitle, null).setContent(this));
    mTabHost.addTab(mTabHost.newTabSpec("tab_music").setIndicator(MusicTitle, null).setContent(this));
    mTabHost.addTab(mTabHost.newTabSpec("tab_record").setIndicator(RecordTitle, null).setContent(this));
    mTabHost.setCurrentTab(0);
    mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            // stopMediaPlayer();
            createTabContent(tabId);
        }
    });
}

From source file:org.telegram.ui.ChatProfileActivity.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (fragmentView == null) {
        fragmentView = inflater.inflate(R.layout.chat_profile_layout, container, false);

        listView = (ListView) fragmentView.findViewById(R.id.listView);
        listView.setAdapter(listViewAdapter = new ListAdapter(parentActivity));
        listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override//from   w ww  .  j a  v  a2 s .  co  m
            public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
                int size = 0;
                if (info != null) {
                    size += info.participants.size();
                }
                if (i > 6 && i < size + 7) {
                    TLRPC.TL_chatParticipant user = info.participants.get(sortedUsers.get(i - 7));
                    if (user.user_id == UserConfig.clientUserId) {
                        return false;
                    }
                    if (info.admin_id != UserConfig.clientUserId
                            && user.inviter_id != UserConfig.clientUserId) {
                        return false;
                    }
                    selectedUser = user;

                    AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
                    CharSequence[] items = new CharSequence[] { getStringEntry(R.string.KickFromGroup) };

                    builder.setItems(items, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            if (i == 0) {
                                kickUser(selectedUser);
                            }
                        }
                    });
                    builder.show().setCanceledOnTouchOutside(true);

                    return true;
                }
                return false;
            }
        });

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                if (i == 2) {
                    SharedPreferences preferences = parentActivity.getSharedPreferences("Notifications",
                            Activity.MODE_PRIVATE);
                    String key = "notify_" + (-chat_id);
                    boolean value = preferences.getBoolean(key, true);
                    SharedPreferences.Editor editor = preferences.edit();
                    editor.putBoolean(key, !value);
                    editor.commit();
                    listView.invalidateViews();
                } else if (i == 3) {
                    try {
                        Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
                        tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,
                                RingtoneManager.TYPE_NOTIFICATION);
                        tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, false);
                        SharedPreferences preferences = parentActivity.getSharedPreferences("Notifications",
                                Activity.MODE_PRIVATE);
                        Uri currentSound = null;

                        String defaultPath = null;
                        Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI;
                        if (defaultUri != null) {
                            defaultPath = defaultUri.getPath();
                        }

                        String path = preferences.getString("sound_chat_path_" + chat_id, defaultPath);
                        if (path != null && !path.equals("NoSound")) {
                            if (path.equals(defaultPath)) {
                                currentSound = defaultUri;
                            } else {
                                currentSound = Uri.parse(path);
                            }
                        }

                        tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound);
                        startActivityForResult(tmpIntent, 15);
                    } catch (Exception e) {
                        FileLog.e("tmessages", e);
                    }
                } else if (i == 5) {
                    MediaActivity fragment = new MediaActivity();
                    Bundle bundle = new Bundle();
                    bundle.putLong("dialog_id", -chat_id);
                    fragment.setArguments(bundle);
                    ((ApplicationActivity) parentActivity).presentFragment(fragment, "media_chat_" + chat_id,
                            false);
                } else {
                    int size = 0;
                    if (info != null) {
                        size += info.participants.size();
                    }
                    if (i > 6 && i < size + 7) {
                        int user_id = info.participants.get(sortedUsers.get(i - 7)).user_id;
                        if (user_id == UserConfig.clientUserId) {
                            return;
                        }
                        UserProfileActivity fragment = new UserProfileActivity();
                        Bundle args = new Bundle();
                        args.putInt("user_id", user_id);
                        fragment.setArguments(args);
                        ((ApplicationActivity) parentActivity).presentFragment(fragment, "user_" + user_id,
                                false);
                    } else {
                        if (size + 7 == i) {
                            if (info.participants.size() < 200) {
                                openAddMenu();
                            } else {
                                kickUser(null);
                            }
                        } else if (size + 7 == i + 1) {
                            kickUser(null);
                        }
                    }
                }
            }
        });

        listView.setOnTouchListener(new OnSwipeTouchListener() {
            public void onSwipeRight() {
                finishFragment(true);
            }
        });
    } else {
        ViewGroup parent = (ViewGroup) fragmentView.getParent();
        if (parent != null) {
            parent.removeView(fragmentView);
        }
    }
    return fragmentView;
}

From source file:support.plus.reportit.SettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // Default config

    if (savedInstanceState != null) {
        // Restore value of members from saved state
        userName = savedInstanceState.getString(userName);
        userBossName = savedInstanceState.getString(userBossName);
    } else {/*from   ww  w. ja va2 s.  c om*/
        // Probably initialize members with default values for a new instance
    }

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

    Toolbar toolbar = (Toolbar) findViewById(R.id.settings_toolbar);
    setSupportActionBar(toolbar);
    toolbar.setTitle(R.string.app_name);
    toolbar.setNavigationIcon(R.drawable.ic_back);

    final TextView TextuserName = (TextView) findViewById(R.id.userName);
    final TextView TextuserBossName = (TextView) findViewById(R.id.userBossName);
    final EditText inuserName = (EditText) findViewById(R.id.inuserName);
    final EditText inuserBossName = (EditText) findViewById(R.id.inuserBossName);
    final Switch sNoti = (Switch) findViewById(R.id.sNoti);
    final Button btimePick = (Button) findViewById(R.id.btimePick);
    final Button bSave = (Button) findViewById(R.id.bSave);
    final Switch sfingerprint_activ = (Switch) findViewById(R.id.sfingerprint_activ);
    final Button bsetpassword = (Button) findViewById(R.id.bsetpassword);
    final Switch sdarkTheme = (Switch) findViewById(R.id.sdarkTheme);
    final Button bchooseRingtone = (Button) findViewById(R.id.bringtonePick);

    final SharedPreferences pref3 = getSharedPreferences("Theme", Context.MODE_PRIVATE);
    Boolean themeDark = pref3.getBoolean("darkTheme", false);
    if (themeDark == true) {
        sdarkTheme.setChecked(true);
    } else {
        sdarkTheme.setChecked(false);
    }
    sdarkTheme.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                final SharedPreferences pref3 = getSharedPreferences("Theme", Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = pref3.edit();
                editor.putBoolean("darkTheme", true);
                editor.commit();
                getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
                // Now recreate for it to take effect
                // startActivity(getIntent());
                recreate();
            } else {
                SharedPreferences.Editor editor = pref3.edit();
                editor.putBoolean("darkTheme", false);
                editor.commit();
                getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);
                // Now recreate for it to take effect
                // startActivity(getIntent());
                recreate();
            }
        }
    });

    /*
    SECURITY SETTINGS
     */

    final SharedPreferences pref1 = getSharedPreferences("Fingerprint", Context.MODE_PRIVATE);
    Boolean fingerprintSet = pref1.getBoolean("fingerprintSet", false);
    if (fingerprintSet == true) {
        sfingerprint_activ.setChecked(true);
        bsetpassword.setVisibility(View.VISIBLE);
    } else {
        sfingerprint_activ.setChecked(false);
        bsetpassword.setVisibility(View.GONE);
    }
    sfingerprint_activ.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                SharedPreferences.Editor editor = pref1.edit();
                editor.putBoolean("fingerprintSet", true);
                editor.commit();
                bsetpassword.setVisibility(View.VISIBLE);
            } else {
                SharedPreferences.Editor editor = pref1.edit();
                editor.putBoolean("fingerprintSet", false);
                editor.commit();
                bsetpassword.setVisibility(View.GONE);
            }
        }
    });

    bsetpassword.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new MaterialDialog.Builder(SettingsActivity.this).title(R.string.set_password)
                    .content(R.string.set_password_desc)
                    .inputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD)
                    .inputRange(1, 10)
                    .input(getString(R.string.password), "", new MaterialDialog.InputCallback() {
                        @Override
                        public void onInput(MaterialDialog dialog, CharSequence input) {
                            String name = String.valueOf(input);
                            SharedPreferences pref1 = getSharedPreferences("Fingerprint", Context.MODE_PRIVATE);
                            SharedPreferences.Editor editor = pref1.edit();
                            editor.putString("passwordSet", name);
                            editor.commit();
                            return;
                        }
                    }).positiveText(R.string.set_password).negativeText(R.string.cancel).cancelable(false)
                    .show();
        }

    });

    /*
    END SECURITY SETTINGS
     */

    /*
    NOTIFICATION SETTINGS
     */
    btimePick.setVisibility(View.GONE);
    sNoti.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                btimePick.setVisibility(View.VISIBLE);
                bchooseRingtone.setVisibility(View.VISIBLE);
            } else {
                btimePick.setVisibility(View.GONE);
                bchooseRingtone.setVisibility(View.GONE);
            }
        }
    });

    final SharedPreferences pref4 = getApplicationContext().getSharedPreferences("userNotification",
            MODE_PRIVATE);
    Boolean notificationSet = pref4.getBoolean("alarmSet", false);
    if (notificationSet == true) {
        sNoti.setChecked(true);
        btimePick.setVisibility(View.VISIBLE);
        bchooseRingtone.setVisibility(View.VISIBLE);
    } else {
        sNoti.setChecked(false);
        btimePick.setVisibility(View.GONE);
        bchooseRingtone.setVisibility(View.GONE);
    }
    sNoti.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                SharedPreferences.Editor editor = pref4.edit();
                editor.putBoolean("alarmSet", true);
                editor.commit();
                btimePick.setVisibility(View.VISIBLE);
                bchooseRingtone.setVisibility(View.VISIBLE);

            } else {
                SharedPreferences.Editor editor = pref4.edit();
                editor.putBoolean("alarmSet", false);
                editor.commit();
                btimePick.setVisibility(View.GONE);
                bchooseRingtone.setVisibility(View.GONE);

            }
        }
    });
    bchooseRingtone.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(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, R.string.choose_ringtone);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
            startActivityForResult(intent, 5);
        }
    });

    btimePick.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            DialogFragment newFragment = new TimePickerFragment();
            newFragment.show(getSupportFragmentManager(), "timePicker");
        }
    });

    /*
    END NOTIFICATION SETTINGS
     */

    /*
    SAVE SETTINGS
     */
    bSave.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String saveworkplace = "Student";
            String saveuserBossName = "Boss";
            saveworkplace = inuserName.getText().toString();
            saveuserBossName = inuserBossName.getText().toString();
            TextuserName.setText(getString(R.string.firm_name) + String.valueOf(saveworkplace));
            TextuserBossName.setText(getString(R.string.instructor_name) + String.valueOf(saveuserBossName));
            final SharedPreferences pref2 = getApplicationContext().getSharedPreferences("userData",
                    MODE_APPEND);
            SharedPreferences.Editor editor = pref2.edit();
            editor.putString("userName", saveworkplace);
            editor.putString("userBoss", saveuserBossName);
            editor.putBoolean("data_saved", true);
            editor.commit();
            Snackbar snackbar = Snackbar.make(findViewById(android.R.id.content),
                    "Data saved. Restart the app to see changes.", Snackbar.LENGTH_LONG);
            snackbar.show();
            // finish();
            startActivity(getIntent());
        }
    });
    final SharedPreferences pref2 = getApplicationContext().getSharedPreferences("userData", MODE_APPEND);
    if (pref2.getBoolean("data_saved", true)) {
        String TextuserNameString = pref2.getString("userName", "");
        String TextuserBossNameString = pref2.getString("userBoss", "");
        TextuserName.setText(getString(R.string.firm_name) + String.valueOf(TextuserNameString));
        TextuserBossName.setText(getString(R.string.instructor_name) + String.valueOf(TextuserBossNameString));
        inuserName.setVisibility(View.GONE);
        inuserBossName.setVisibility(View.GONE);
        bSave.setVisibility(View.GONE);

    } else {
        Toast toast = Toast.makeText(this, "No data saved", Toast.LENGTH_SHORT);
        toast.show();
    }
    /*
    END SAVE SETTINGS
     */

}

From source file:org.telegram.ui.NotificationsSettingsActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("NotificationsAndSounds", R.string.NotificationsAndSounds));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override/*from   www  .j a  v a2  s.c  o  m*/
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });

    fragmentView = new FrameLayout(context);
    fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background));
    FrameLayout frameLayout = (FrameLayout) fragmentView;

    listView = new ListView(context);
    listView.setDivider(null);
    listView.setDividerHeight(0);
    listView.setVerticalScrollBarEnabled(false);
    frameLayout.addView(listView);
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    listView.setLayoutParams(layoutParams);
    listView.setAdapter(new ListAdapter(context));
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, final View view, final int i, long l) {
            boolean enabled = false;
            if (i == messageAlertRow || i == groupAlertRow) {
                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = preferences.edit();
                if (i == messageAlertRow) {
                    enabled = preferences.getBoolean("EnableAll", true);
                    editor.putBoolean("EnableAll", !enabled);
                } else if (i == groupAlertRow) {
                    enabled = preferences.getBoolean("EnableGroup", true);
                    editor.putBoolean("EnableGroup", !enabled);
                }
                editor.commit();
                updateServerNotificationsSettings(i == groupAlertRow);
            } else if (i == messagePreviewRow || i == groupPreviewRow) {
                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = preferences.edit();
                if (i == messagePreviewRow) {
                    enabled = preferences.getBoolean("EnablePreviewAll", true);
                    editor.putBoolean("EnablePreviewAll", !enabled);
                } else if (i == groupPreviewRow) {
                    enabled = preferences.getBoolean("EnablePreviewGroup", true);
                    editor.putBoolean("EnablePreviewGroup", !enabled);
                }
                editor.commit();
                updateServerNotificationsSettings(i == groupPreviewRow);
            } else if (i == messageSoundRow || i == groupSoundRow) {
                try {
                    SharedPreferences preferences = ApplicationLoader.applicationContext
                            .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                    Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
                    tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
                    tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
                    tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI,
                            RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
                    Uri currentSound = null;

                    String defaultPath = null;
                    Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI;
                    if (defaultUri != null) {
                        defaultPath = defaultUri.getPath();
                    }

                    if (i == messageSoundRow) {
                        String path = preferences.getString("GlobalSoundPath", defaultPath);
                        if (path != null && !path.equals("NoSound")) {
                            if (path.equals(defaultPath)) {
                                currentSound = defaultUri;
                            } else {
                                currentSound = Uri.parse(path);
                            }
                        }
                    } else if (i == groupSoundRow) {
                        String path = preferences.getString("GroupSoundPath", defaultPath);
                        if (path != null && !path.equals("NoSound")) {
                            if (path.equals(defaultPath)) {
                                currentSound = defaultUri;
                            } else {
                                currentSound = Uri.parse(path);
                            }
                        }
                    }
                    tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound);
                    startActivityForResult(tmpIntent, i);
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
            } else if (i == resetNotificationsRow) {
                if (reseting) {
                    return;
                }
                reseting = true;
                TLRPC.TL_account_resetNotifySettings req = new TLRPC.TL_account_resetNotifySettings();
                ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
                    @Override
                    public void run(TLObject response, TLRPC.TL_error error) {
                        AndroidUtilities.runOnUIThread(new Runnable() {
                            @Override
                            public void run() {
                                MessagesController.getInstance().enableJoined = true;
                                reseting = false;
                                SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                SharedPreferences.Editor editor = preferences.edit();
                                editor.clear();
                                editor.commit();
                                if (listView != null) {
                                    listView.invalidateViews();
                                }
                                if (getParentActivity() != null) {
                                    Toast toast = Toast
                                            .makeText(getParentActivity(),
                                                    LocaleController.getString("ResetNotificationsText",
                                                            R.string.ResetNotificationsText),
                                                    Toast.LENGTH_SHORT);
                                    toast.show();
                                }
                            }
                        });
                    }
                });
            } else if (i == inappSoundRow) {
                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = preferences.edit();
                enabled = preferences.getBoolean("EnableInAppSounds", true);
                editor.putBoolean("EnableInAppSounds", !enabled);
                editor.commit();
            } else if (i == inappVibrateRow) {
                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = preferences.edit();
                enabled = preferences.getBoolean("EnableInAppVibrate", true);
                editor.putBoolean("EnableInAppVibrate", !enabled);
                editor.commit();
            } else if (i == inappPreviewRow) {
                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = preferences.edit();
                enabled = preferences.getBoolean("EnableInAppPreview", true);
                editor.putBoolean("EnableInAppPreview", !enabled);
                editor.commit();
            } else if (i == inchatSoundRow) {
                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = preferences.edit();
                enabled = preferences.getBoolean("EnableInChatSound", true);
                editor.putBoolean("EnableInChatSound", !enabled);
                editor.commit();
                NotificationsController.getInstance().setInChatSoundEnabled(!enabled);
            } else if (i == inappPriorityRow) {
                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = preferences.edit();
                enabled = preferences.getBoolean("EnableInAppPriority", false);
                editor.putBoolean("EnableInAppPriority", !enabled);
                editor.commit();
            } else if (i == contactJoinedRow) {
                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = preferences.edit();
                enabled = preferences.getBoolean("EnableContactJoined", true);
                MessagesController.getInstance().enableJoined = !enabled;
                editor.putBoolean("EnableContactJoined", !enabled);
                editor.commit();
            } else if (i == pinnedMessageRow) {
                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = preferences.edit();
                enabled = preferences.getBoolean("PinnedMessages", true);
                editor.putBoolean("PinnedMessages", !enabled);
                editor.commit();
            } else if (i == androidAutoAlertRow) {
                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = preferences.edit();
                enabled = preferences.getBoolean("EnableAutoNotifications", false);
                editor.putBoolean("EnableAutoNotifications", !enabled);
                editor.commit();
            } else if (i == badgeNumberRow) {
                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = preferences.edit();
                enabled = preferences.getBoolean("badgeNumber", true);
                editor.putBoolean("badgeNumber", !enabled);
                editor.commit();
                NotificationsController.getInstance().setBadgeEnabled(!enabled);
            } else if (i == notificationsServiceConnectionRow) {
                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                enabled = preferences.getBoolean("pushConnection", true);
                SharedPreferences.Editor editor = preferences.edit();
                editor.putBoolean("pushConnection", !enabled);
                editor.commit();
                if (!enabled) {
                    ConnectionsManager.getInstance().setPushConnectionEnabled(true);
                } else {
                    ConnectionsManager.getInstance().setPushConnectionEnabled(false);
                }
            } else if (i == notificationsServiceRow) {
                final SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                enabled = preferences.getBoolean("pushService", true);
                SharedPreferences.Editor editor = preferences.edit();
                editor.putBoolean("pushService", !enabled);
                editor.commit();
                if (!enabled) {
                    ApplicationLoader.startPushService();
                } else {
                    ApplicationLoader.stopPushService();
                }
                /*if (!enabled) {
                        
                } else {
                if (getParentActivity() == null) {
                    return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setMessage(LocaleController.getString("NotificationsServiceDisableInfo", R.string.NotificationsServiceDisableInfo));
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        
                        final SharedPreferences.Editor editor = preferences.edit();
                        editor.putBoolean("pushService", false);
                        editor.commit();
                        listView.invalidateViews();
                    }
                });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        ((TextCheckCell) view).setChecked(true);
                    }
                });
                showDialog(builder.create());
                }*/
            } else if (i == messageLedRow || i == groupLedRow) {
                if (getParentActivity() == null) {
                    return;
                }

                LinearLayout linearLayout = new LinearLayout(getParentActivity());
                linearLayout.setOrientation(LinearLayout.VERTICAL);
                final ColorPickerView colorPickerView = new ColorPickerView(getParentActivity());
                linearLayout.addView(colorPickerView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT,
                        LayoutHelper.WRAP_CONTENT, Gravity.CENTER));

                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                if (i == messageLedRow) {
                    colorPickerView.setOldCenterColor(preferences.getInt("MessagesLed", 0xff00ff00));
                } else if (i == groupLedRow) {
                    colorPickerView.setOldCenterColor(preferences.getInt("GroupLed", 0xff00ff00));
                }

                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("LedColor", R.string.LedColor));
                builder.setView(linearLayout);
                builder.setPositiveButton(LocaleController.getString("Set", R.string.Set),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int which) {
                                final SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                SharedPreferences.Editor editor = preferences.edit();
                                TextColorCell textCell = (TextColorCell) view;
                                if (i == messageLedRow) {
                                    editor.putInt("MessagesLed", colorPickerView.getColor());
                                    textCell.setTextAndColor(
                                            LocaleController.getString("LedColor", R.string.LedColor),
                                            colorPickerView.getColor(), true);
                                } else if (i == groupLedRow) {
                                    editor.putInt("GroupLed", colorPickerView.getColor());
                                    textCell.setTextAndColor(
                                            LocaleController.getString("LedColor", R.string.LedColor),
                                            colorPickerView.getColor(), true);
                                }
                                editor.commit();
                            }
                        });
                builder.setNeutralButton(LocaleController.getString("LedDisabled", R.string.LedDisabled),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                final SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                SharedPreferences.Editor editor = preferences.edit();
                                TextColorCell textCell = (TextColorCell) view;
                                if (i == messageLedRow) {
                                    editor.putInt("MessagesLed", 0);
                                    textCell.setTextAndColor(
                                            LocaleController.getString("LedColor", R.string.LedColor), 0, true);
                                } else if (i == groupLedRow) {
                                    editor.putInt("GroupLed", 0);
                                    textCell.setTextAndColor(
                                            LocaleController.getString("LedColor", R.string.LedColor), 0, true);
                                }
                                editor.commit();
                                listView.invalidateViews();
                            }
                        });
                showDialog(builder.create());
            } else if (i == messagePopupNotificationRow || i == groupPopupNotificationRow) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("PopupNotification", R.string.PopupNotification));
                builder.setItems(
                        new CharSequence[] { LocaleController.getString("NoPopup", R.string.NoPopup),
                                LocaleController.getString("OnlyWhenScreenOn", R.string.OnlyWhenScreenOn),
                                LocaleController.getString("OnlyWhenScreenOff", R.string.OnlyWhenScreenOff),
                                LocaleController.getString("AlwaysShowPopup", R.string.AlwaysShowPopup) },
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                SharedPreferences.Editor editor = preferences.edit();
                                if (i == messagePopupNotificationRow) {
                                    editor.putInt("popupAll", which);
                                } else if (i == groupPopupNotificationRow) {
                                    editor.putInt("popupGroup", which);
                                }
                                editor.commit();
                                if (listView != null) {
                                    listView.invalidateViews();
                                }
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            } else if (i == messageVibrateRow || i == groupVibrateRow) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("Vibrate", R.string.Vibrate));
                builder.setItems(
                        new CharSequence[] {
                                LocaleController.getString("VibrationDisabled", R.string.VibrationDisabled),
                                LocaleController.getString("VibrationDefault", R.string.VibrationDefault),
                                LocaleController.getString("Short", R.string.Short),
                                LocaleController.getString("Long", R.string.Long),
                                LocaleController.getString("OnlyIfSilent", R.string.OnlyIfSilent) },
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                SharedPreferences.Editor editor = preferences.edit();
                                String param = "vibrate_messages";
                                if (i == groupVibrateRow) {
                                    param = "vibrate_group";
                                }
                                if (which == 0) {
                                    editor.putInt(param, 2);
                                } else if (which == 1) {
                                    editor.putInt(param, 0);
                                } else if (which == 2) {
                                    editor.putInt(param, 1);
                                } else if (which == 3) {
                                    editor.putInt(param, 3);
                                } else if (which == 4) {
                                    editor.putInt(param, 4);
                                }
                                editor.commit();
                                if (listView != null) {
                                    listView.invalidateViews();
                                }
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            } else if (i == messagePriorityRow || i == groupPriorityRow) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(
                        LocaleController.getString("NotificationsPriority", R.string.NotificationsPriority));
                builder.setItems(new CharSequence[] {
                        LocaleController.getString("NotificationsPriorityDefault",
                                R.string.NotificationsPriorityDefault),
                        LocaleController.getString("NotificationsPriorityHigh",
                                R.string.NotificationsPriorityHigh),
                        LocaleController.getString("NotificationsPriorityMax",
                                R.string.NotificationsPriorityMax) },
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                if (i == messagePriorityRow) {
                                    preferences.edit().putInt("priority_messages", which).commit();
                                } else if (i == groupPriorityRow) {
                                    preferences.edit().putInt("priority_group", which).commit();
                                }
                                if (listView != null) {
                                    listView.invalidateViews();
                                }
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            } else if (i == repeatRow) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(
                        LocaleController.getString("RepeatNotifications", R.string.RepeatNotifications));
                builder.setItems(
                        new CharSequence[] {
                                LocaleController.getString("RepeatDisabled", R.string.RepeatDisabled),
                                LocaleController.formatPluralString("Minutes", 5),
                                LocaleController.formatPluralString("Minutes", 10),
                                LocaleController.formatPluralString("Minutes", 30),
                                LocaleController.formatPluralString("Hours", 1),
                                LocaleController.formatPluralString("Hours", 2),
                                LocaleController.formatPluralString("Hours", 4) },
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                int minutes = 0;
                                if (which == 1) {
                                    minutes = 5;
                                } else if (which == 2) {
                                    minutes = 10;
                                } else if (which == 3) {
                                    minutes = 30;
                                } else if (which == 4) {
                                    minutes = 60;
                                } else if (which == 5) {
                                    minutes = 60 * 2;
                                } else if (which == 6) {
                                    minutes = 60 * 4;
                                }
                                SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                preferences.edit().putInt("repeat_messages", minutes).commit();
                                if (listView != null) {
                                    listView.invalidateViews();
                                }
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            }
            if (view instanceof TextCheckCell) {
                ((TextCheckCell) view).setChecked(!enabled);
            }
        }
    });

    return fragmentView;
}

From source file:com.geoffreybuttercrumbs.arewethereyet.DrawerFragment.java

protected void ringtonepicker() {
    Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_ALARM);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Tone");
    if (uri != null) {
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, uri);
    } else {/*from  w  ww  .  j ava2s. c om*/
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
    }
    startActivityForResult(intent, Set_Ringtone);
    SlidingFragmentActivity sfa = (SlidingFragmentActivity) getActivity();
    sfa.showContent();
}

From source file:org.telegram.ui.ProfileNotificationsActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("NotificationsAndSounds", R.string.NotificationsAndSounds));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override//ww w  .j ava  2  s .c om
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });

    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));

    listView = new ListView(context);
    listView.setDivider(null);
    listView.setDividerHeight(0);
    listView.setVerticalScrollBarEnabled(false);
    AndroidUtilities.setListViewEdgeEffectColor(listView, AvatarDrawable.getProfileBackColorForId(5));
    frameLayout.addView(listView);
    final FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    listView.setLayoutParams(layoutParams);
    listView.setAdapter(new ListAdapter(context));
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
            if (i == settingsVibrateRow) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("Vibrate", R.string.Vibrate));
                builder.setItems(
                        new CharSequence[] {
                                LocaleController.getString("VibrationDisabled", R.string.VibrationDisabled),
                                LocaleController.getString("SettingsDefault", R.string.SettingsDefault),
                                LocaleController.getString("SystemDefault", R.string.SystemDefault),
                                LocaleController.getString("Short", R.string.Short),
                                LocaleController.getString("Long", R.string.Long) },
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                SharedPreferences.Editor editor = preferences.edit();
                                if (which == 0) {
                                    editor.putInt("vibrate_" + dialog_id, 2);
                                } else if (which == 1) {
                                    editor.putInt("vibrate_" + dialog_id, 0);
                                } else if (which == 2) {
                                    editor.putInt("vibrate_" + dialog_id, 4);
                                } else if (which == 3) {
                                    editor.putInt("vibrate_" + dialog_id, 1);
                                } else if (which == 4) {
                                    editor.putInt("vibrate_" + dialog_id, 3);
                                }
                                editor.commit();
                                if (listView != null) {
                                    listView.invalidateViews();
                                }
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            } else if (i == settingsNotificationsRow) {
                if (getParentActivity() == null) {
                    return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setItems(
                        new CharSequence[] { LocaleController.getString("Default", R.string.Default),
                                LocaleController.getString("Enabled", R.string.Enabled),
                                LocaleController.getString("NotificationsDisabled",
                                        R.string.NotificationsDisabled) },
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface d, int which) {
                                SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                SharedPreferences.Editor editor = preferences.edit();
                                editor.putInt("notify2_" + dialog_id, which);
                                if (which == 2) {
                                    NotificationsController.getInstance()
                                            .removeNotificationsForDialog(dialog_id);
                                }
                                MessagesStorage.getInstance().setDialogFlags(dialog_id, which == 2 ? 1 : 0);
                                editor.commit();
                                TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs_dict
                                        .get(dialog_id);
                                if (dialog != null) {
                                    dialog.notify_settings = new TLRPC.TL_peerNotifySettings();
                                    if (which == 2) {
                                        dialog.notify_settings.mute_until = Integer.MAX_VALUE;
                                    }
                                }
                                if (listView != null) {
                                    listView.invalidateViews();
                                }
                                NotificationsController.updateServerNotificationsSettings(dialog_id);
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            } else if (i == settingsSoundRow) {
                try {
                    Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
                    tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
                    tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
                    tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI,
                            RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
                    SharedPreferences preferences = ApplicationLoader.applicationContext
                            .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                    Uri currentSound = null;

                    String defaultPath = null;
                    Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI;
                    if (defaultUri != null) {
                        defaultPath = defaultUri.getPath();
                    }

                    String path = preferences.getString("sound_path_" + dialog_id, defaultPath);
                    if (path != null && !path.equals("NoSound")) {
                        if (path.equals(defaultPath)) {
                            currentSound = defaultUri;
                        } else {
                            currentSound = Uri.parse(path);
                        }
                    }

                    tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound);
                    startActivityForResult(tmpIntent, 12);
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
            } else if (i == settingsLedRow) {
                if (getParentActivity() == null) {
                    return;
                }

                LinearLayout linearLayout = new LinearLayout(getParentActivity());
                linearLayout.setOrientation(LinearLayout.VERTICAL);
                final ColorPickerView colorPickerView = new ColorPickerView(getParentActivity());
                linearLayout.addView(colorPickerView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT,
                        LayoutHelper.WRAP_CONTENT, Gravity.CENTER));

                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                if (preferences.contains("color_" + dialog_id)) {
                    colorPickerView.setOldCenterColor(preferences.getInt("color_" + dialog_id, 0xff00ff00));
                } else {
                    if ((int) dialog_id < 0) {
                        colorPickerView.setOldCenterColor(preferences.getInt("GroupLed", 0xff00ff00));
                    } else {
                        colorPickerView.setOldCenterColor(preferences.getInt("MessagesLed", 0xff00ff00));
                    }
                }

                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("LedColor", R.string.LedColor));
                builder.setView(linearLayout);
                builder.setPositiveButton(LocaleController.getString("Set", R.string.Set),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int which) {
                                final SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                SharedPreferences.Editor editor = preferences.edit();
                                editor.putInt("color_" + dialog_id, colorPickerView.getColor());
                                editor.commit();
                                listView.invalidateViews();
                            }
                        });
                builder.setNeutralButton(LocaleController.getString("LedDisabled", R.string.LedDisabled),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                final SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                SharedPreferences.Editor editor = preferences.edit();
                                editor.putInt("color_" + dialog_id, 0);
                                editor.commit();
                                listView.invalidateViews();
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Default", R.string.Default),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                final SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                SharedPreferences.Editor editor = preferences.edit();
                                editor.remove("color_" + dialog_id);
                                editor.commit();
                                listView.invalidateViews();
                            }
                        });
                showDialog(builder.create());
            } else if (i == settingsPriorityRow) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(
                        LocaleController.getString("NotificationsPriority", R.string.NotificationsPriority));
                builder.setItems(
                        new CharSequence[] {
                                LocaleController.getString("SettingsDefault", R.string.SettingsDefault),
                                LocaleController.getString("NotificationsPriorityDefault",
                                        R.string.NotificationsPriorityDefault),
                                LocaleController.getString("NotificationsPriorityHigh",
                                        R.string.NotificationsPriorityHigh),
                                LocaleController.getString("NotificationsPriorityMax",
                                        R.string.NotificationsPriorityMax) },
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                if (which == 0) {
                                    which = 3;
                                } else {
                                    which--;
                                }
                                SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                preferences.edit().putInt("priority_" + dialog_id, which).commit();
                                if (listView != null) {
                                    listView.invalidateViews();
                                }
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            } else if (i == smartRow) {
                if (getParentActivity() == null) {
                    return;
                }
                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                int notifyMaxCount = preferences.getInt("smart_max_count_" + dialog_id, 2);
                int notifyDelay = preferences.getInt("smart_delay_" + dialog_id, 3 * 60);
                if (notifyMaxCount == 0) {
                    notifyMaxCount = 2;
                }

                LinearLayout linearLayout = new LinearLayout(getParentActivity());
                linearLayout.setOrientation(LinearLayout.VERTICAL);

                LinearLayout linearLayout2 = new LinearLayout(getParentActivity());
                linearLayout2.setOrientation(LinearLayout.HORIZONTAL);
                linearLayout.addView(linearLayout2);
                LinearLayout.LayoutParams layoutParams1 = (LinearLayout.LayoutParams) linearLayout2
                        .getLayoutParams();
                layoutParams1.width = LayoutHelper.WRAP_CONTENT;
                layoutParams1.height = LayoutHelper.WRAP_CONTENT;
                layoutParams1.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
                linearLayout2.setLayoutParams(layoutParams1);

                TextView textView = new TextView(getParentActivity());
                textView.setText(LocaleController.getString("SmartNotificationsSoundAtMost",
                        R.string.SmartNotificationsSoundAtMost));
                textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
                linearLayout2.addView(textView);
                layoutParams1 = (LinearLayout.LayoutParams) textView.getLayoutParams();
                layoutParams1.width = LayoutHelper.WRAP_CONTENT;
                layoutParams1.height = LayoutHelper.WRAP_CONTENT;
                layoutParams1.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT;
                textView.setLayoutParams(layoutParams1);

                final NumberPicker numberPickerTimes = new NumberPicker(getParentActivity());
                numberPickerTimes.setMinValue(1);
                numberPickerTimes.setMaxValue(10);
                numberPickerTimes.setValue(notifyMaxCount);
                linearLayout2.addView(numberPickerTimes);
                layoutParams1 = (LinearLayout.LayoutParams) numberPickerTimes.getLayoutParams();
                layoutParams1.width = AndroidUtilities.dp(50);
                numberPickerTimes.setLayoutParams(layoutParams1);

                textView = new TextView(getParentActivity());
                textView.setText(LocaleController.getString("SmartNotificationsTimes",
                        R.string.SmartNotificationsTimes));
                textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
                linearLayout2.addView(textView);
                layoutParams1 = (LinearLayout.LayoutParams) textView.getLayoutParams();
                layoutParams1.width = LayoutHelper.WRAP_CONTENT;
                layoutParams1.height = LayoutHelper.WRAP_CONTENT;
                layoutParams1.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT;
                textView.setLayoutParams(layoutParams1);

                linearLayout2 = new LinearLayout(getParentActivity());
                linearLayout2.setOrientation(LinearLayout.HORIZONTAL);
                linearLayout.addView(linearLayout2);
                layoutParams1 = (LinearLayout.LayoutParams) linearLayout2.getLayoutParams();
                layoutParams1.width = LayoutHelper.WRAP_CONTENT;
                layoutParams1.height = LayoutHelper.WRAP_CONTENT;
                layoutParams1.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
                linearLayout2.setLayoutParams(layoutParams1);

                textView = new TextView(getParentActivity());
                textView.setText(LocaleController.getString("SmartNotificationsWithin",
                        R.string.SmartNotificationsWithin));
                textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
                linearLayout2.addView(textView);
                layoutParams1 = (LinearLayout.LayoutParams) textView.getLayoutParams();
                layoutParams1.width = LayoutHelper.WRAP_CONTENT;
                layoutParams1.height = LayoutHelper.WRAP_CONTENT;
                layoutParams1.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT;
                textView.setLayoutParams(layoutParams1);

                final NumberPicker numberPickerMinutes = new NumberPicker(getParentActivity());
                numberPickerMinutes.setMinValue(1);
                numberPickerMinutes.setMaxValue(10);
                numberPickerMinutes.setValue(notifyDelay / 60);
                linearLayout2.addView(numberPickerMinutes);
                layoutParams1 = (LinearLayout.LayoutParams) numberPickerMinutes.getLayoutParams();
                layoutParams1.width = AndroidUtilities.dp(50);
                numberPickerMinutes.setLayoutParams(layoutParams1);

                textView = new TextView(getParentActivity());
                textView.setText(LocaleController.getString("SmartNotificationsMinutes",
                        R.string.SmartNotificationsMinutes));
                textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
                linearLayout2.addView(textView);
                layoutParams1 = (LinearLayout.LayoutParams) textView.getLayoutParams();
                layoutParams1.width = LayoutHelper.WRAP_CONTENT;
                layoutParams1.height = LayoutHelper.WRAP_CONTENT;
                layoutParams1.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT;
                textView.setLayoutParams(layoutParams1);

                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("SmartNotifications", R.string.SmartNotifications));
                builder.setView(linearLayout);
                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                preferences.edit()
                                        .putInt("smart_max_count_" + dialog_id, numberPickerTimes.getValue())
                                        .commit();
                                preferences.edit()
                                        .putInt("smart_delay_" + dialog_id, numberPickerMinutes.getValue() * 60)
                                        .commit();
                                if (listView != null) {
                                    listView.invalidateViews();
                                }
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("SmartNotificationsDisabled",
                        R.string.SmartNotificationsDisabled), new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                SharedPreferences preferences = ApplicationLoader.applicationContext
                                        .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
                                preferences.edit().putInt("smart_max_count_" + dialog_id, 0).commit();
                                if (listView != null) {
                                    listView.invalidateViews();
                                }
                            }
                        });
                showDialog(builder.create());
            }
        }
    });

    return fragmentView;
}

From source file:nkarasch.repeatingreminder.gui.AlertView.java

@OnClick(R.id.text_tone)
public void toneOnClick() {
    Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Tone");
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
    mContext.getIntent().putExtra("array_index", mPosition);
    mContext.startActivityForResult(intent, 5);
    stopAlert();//from   w w  w .  j av a2s  .  c o m
}